Fixed sort key to not sort by an un-indexed field by default
* Added indices on domain, record and recordset tables for created_at * Removed redundent extra sort param in _find() Partially-Fixes: #1413472 Change-Id: Ic6c4274b0ce3d6c14ce02666df945aec1f838cc7
This commit is contained in:
parent
4620275cdb
commit
6425b3f8d3
@ -242,7 +242,7 @@ class SQLAlchemy(object):
|
|||||||
try:
|
try:
|
||||||
query = utils.paginate_query(
|
query = utils.paginate_query(
|
||||||
query, table, limit,
|
query, table, limit,
|
||||||
[sort_key, 'id', 'created_at'], marker=marker,
|
[sort_key, 'id'], marker=marker,
|
||||||
sort_dir=sort_dir)
|
sort_dir=sort_dir)
|
||||||
|
|
||||||
resultproxy = self.session.execute(query)
|
resultproxy = self.session.execute(query)
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
# Copyright (c) 2014 Rackspace Inc.
|
||||||
|
#
|
||||||
|
# Author: Tim Simmons <tim.simmons@rackspace.com>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
from sqlalchemy import Index, MetaData, Table
|
||||||
|
|
||||||
|
meta = MetaData()
|
||||||
|
|
||||||
|
|
||||||
|
def index_exists(index):
|
||||||
|
table = index[1]._get_table()
|
||||||
|
cols = sorted([str(x).split('.')[1] for x in index[1:]])
|
||||||
|
|
||||||
|
for idx in table.indexes:
|
||||||
|
if sorted(idx.columns.keys()) == cols:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade(migrate_engine):
|
||||||
|
|
||||||
|
meta.bind = migrate_engine
|
||||||
|
|
||||||
|
zones_table = Table('domains', meta, autoload=True)
|
||||||
|
recordsets_table = Table('recordsets', meta, autoload=True)
|
||||||
|
records_table = Table('records', meta, autoload=True)
|
||||||
|
|
||||||
|
indices = [
|
||||||
|
['zone_created_at', zones_table.c.created_at],
|
||||||
|
['recordset_created_at', recordsets_table.c.created_at],
|
||||||
|
['record_created_at', records_table.c.created_at]
|
||||||
|
]
|
||||||
|
|
||||||
|
for ind in indices:
|
||||||
|
if not index_exists(ind):
|
||||||
|
index = Index(*ind)
|
||||||
|
index.create(migrate_engine)
|
Loading…
Reference in New Issue
Block a user