mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-11-08 14:40:27 +00:00
Merge pull request #1379 from raunz/dashboard_improvements
Fix dashboard MySQL performance with large history for standard users
This commit is contained in:
commit
062cb032c5
@ -165,19 +165,24 @@ def dashboard():
|
||||
history_number = History.query.count()
|
||||
history = History.query.order_by(History.created_on.desc()).limit(4).all()
|
||||
elif Setting().get('allow_user_view_history'):
|
||||
history = db.session.query(History) \
|
||||
.join(Domain, History.domain_id == Domain.id) \
|
||||
allowed_domain_id_subquery = db.session.query(Domain.id) \
|
||||
.outerjoin(DomainUser, Domain.id == DomainUser.domain_id) \
|
||||
.outerjoin(Account, Domain.account_id == Account.id) \
|
||||
.outerjoin(AccountUser, Account.id == AccountUser.account_id) \
|
||||
.order_by(History.created_on.desc()) \
|
||||
.filter(
|
||||
db.or_(
|
||||
.filter(db.or_(
|
||||
DomainUser.user_id == current_user.id,
|
||||
AccountUser.user_id == current_user.id
|
||||
)).all()
|
||||
history_number = len(history) # history.count()
|
||||
history = history[:4]
|
||||
)) \
|
||||
.subquery()
|
||||
history = db.session.query(History) \
|
||||
.with_hint(History, "FORCE INDEX (ix_history_created_on)", 'mysql') \
|
||||
.order_by(History.created_on.desc()) \
|
||||
.filter(History.domain_id.in_(allowed_domain_id_subquery)) \
|
||||
.limit(4) \
|
||||
.all()
|
||||
history_number = db.session.query(History) \
|
||||
.filter(History.domain_id.in_(allowed_domain_id_subquery)) \
|
||||
.count()
|
||||
domain_count = db.session.query(Domain) \
|
||||
.outerjoin(DomainUser, Domain.id == DomainUser.domain_id) \
|
||||
.outerjoin(Account, Domain.account_id == Account.id) \
|
||||
|
Loading…
Reference in New Issue
Block a user