mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2025-01-07 10:55:40 +00:00
Records entries should not required database requests for domain listing page
Create a new class just for storing records entries, without the Setting lookup otherwise for each record it will make 4 SQL queries to retrieve something that is not used.
This commit is contained in:
parent
9f29a8e154
commit
8698009c30
@ -1377,6 +1377,29 @@ class AccountUser(db.Model):
|
|||||||
return '<Account_User {0} {1}>'.format(self.account_id, self.user_id)
|
return '<Account_User {0} {1}>'.format(self.account_id, self.user_id)
|
||||||
|
|
||||||
|
|
||||||
|
class RecordEntry(object):
|
||||||
|
"""
|
||||||
|
This is not a model, it's just an object
|
||||||
|
which will store records entries from PowerDNS API
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, name=None, type=None, status=None, ttl=None, data=None,
|
||||||
|
is_allowed_edit=False):
|
||||||
|
self.name = name
|
||||||
|
self.type = type
|
||||||
|
self.status = status
|
||||||
|
self.ttl = ttl
|
||||||
|
self.data = data
|
||||||
|
self._is_allowed_edit = is_allowed_edit
|
||||||
|
self._is_allowed_delete = is_allowed_edit and self.type != 'SOA'
|
||||||
|
|
||||||
|
def is_allowed_edit(self):
|
||||||
|
return self._is_allowed_edit
|
||||||
|
|
||||||
|
def is_allowed_delete(self):
|
||||||
|
return self._is_allowed_delete
|
||||||
|
|
||||||
|
|
||||||
class Record(object):
|
class Record(object):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -18,7 +18,7 @@ from flask import g, request, make_response, jsonify, render_template, session,
|
|||||||
from flask_login import login_user, logout_user, current_user, login_required
|
from flask_login import login_user, logout_user, current_user, login_required
|
||||||
from werkzeug import secure_filename
|
from werkzeug import secure_filename
|
||||||
|
|
||||||
from .models import User, Account, AccountUser, Domain, Record, Role, Server, History, Anonymous, Setting, DomainSetting, DomainTemplate, DomainTemplateRecord
|
from .models import User, Account, AccountUser, Domain, Record, RecordEntry, Role, Server, History, Anonymous, Setting, DomainSetting, DomainTemplate, DomainTemplateRecord
|
||||||
from app import app, login_manager, csrf
|
from app import app, login_manager, csrf
|
||||||
from app.lib import utils
|
from app.lib import utils
|
||||||
from app.oauth import github_oauth, google_oauth, oidc_oauth
|
from app.oauth import github_oauth, google_oauth, oidc_oauth
|
||||||
@ -775,7 +775,7 @@ def domain(domain_name):
|
|||||||
for jr in jrecords:
|
for jr in jrecords:
|
||||||
if jr['type'] in records_allow_to_edit:
|
if jr['type'] in records_allow_to_edit:
|
||||||
for subrecord in jr['records']:
|
for subrecord in jr['records']:
|
||||||
record = Record(name=jr['name'], type=jr['type'], status='Disabled' if subrecord['disabled'] else 'Active', ttl=jr['ttl'], data=subrecord['content'])
|
record = RecordEntry(name=jr['name'], type=jr['type'], status='Disabled' if subrecord['disabled'] else 'Active', ttl=jr['ttl'], data=subrecord['content'], is_allowed_edit=True)
|
||||||
records.append(record)
|
records.append(record)
|
||||||
if not re.search('ip6\.arpa|in-addr\.arpa$', domain_name):
|
if not re.search('ip6\.arpa|in-addr\.arpa$', domain_name):
|
||||||
editable_records = forward_records_allow_to_edit
|
editable_records = forward_records_allow_to_edit
|
||||||
@ -785,7 +785,7 @@ def domain(domain_name):
|
|||||||
else:
|
else:
|
||||||
for jr in jrecords:
|
for jr in jrecords:
|
||||||
if jr['type'] in records_allow_to_edit:
|
if jr['type'] in records_allow_to_edit:
|
||||||
record = Record(name=jr['name'], type=jr['type'], status='Disabled' if jr['disabled'] else 'Active', ttl=jr['ttl'], data=jr['content'])
|
record = RecordEntry(name=jr['name'], type=jr['type'], status='Disabled' if jr['disabled'] else 'Active', ttl=jr['ttl'], data=jr['content'], is_allowed_edit=True)
|
||||||
records.append(record)
|
records.append(record)
|
||||||
if not re.search('ip6\.arpa|in-addr\.arpa$', domain_name):
|
if not re.search('ip6\.arpa|in-addr\.arpa$', domain_name):
|
||||||
editable_records = forward_records_allow_to_edit
|
editable_records = forward_records_allow_to_edit
|
||||||
|
Loading…
Reference in New Issue
Block a user