mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 14:40:00 +00:00
improve performance
This commit is contained in:
parent
847800c23e
commit
2b3d2f2479
|
@ -42,6 +42,7 @@ def upgrade():
|
|||
op.drop_index('ix_nyaa_torrents_flags', table_name='nyaa_torrents')
|
||||
op.create_index(op.f('ix_nyaa_torrents_uploader_id'), 'nyaa_torrents', ['uploader_id'], unique=False)
|
||||
op.drop_index('uploader_flag_idx', table_name='nyaa_torrents')
|
||||
op.create_index('ix_nyaa_super', 'nyaa_torrents', ['id', 'uploader_id', 'main_category_id', 'sub_category_id', 'anonymous', 'hidden', 'deleted', 'banned', 'trusted', 'remake', 'complete'], unique=False)
|
||||
|
||||
op.execute('UPDATE nyaa_torrents SET anonymous = TRUE WHERE flags & 1 IS TRUE;')
|
||||
op.execute('UPDATE nyaa_torrents SET hidden = TRUE WHERE flags & 2 IS TRUE;')
|
||||
|
@ -52,7 +53,7 @@ def upgrade():
|
|||
op.execute('UPDATE nyaa_torrents SET banned = TRUE WHERE flags & 64 IS TRUE;')
|
||||
op.execute('UPDATE nyaa_torrents SET comment_locked = TRUE WHERE flags & 128 IS TRUE;')
|
||||
|
||||
op.drop_column('nyaa_torrents', 'flags')
|
||||
#op.drop_column('nyaa_torrents', 'flags')
|
||||
|
||||
op.execute(
|
||||
"ALTER TABLE sukebei_torrents "
|
||||
|
@ -78,6 +79,7 @@ def upgrade():
|
|||
op.drop_index('ix_sukebei_torrents_flags', table_name='sukebei_torrents')
|
||||
op.create_index(op.f('ix_sukebei_torrents_uploader_id'), 'sukebei_torrents', ['uploader_id'], unique=False)
|
||||
op.drop_index('uploader_flag_idx', table_name='sukebei_torrents')
|
||||
op.create_index('ix_sukebei_super', 'sukebei_torrents', ['id', 'uploader_id', 'main_category_id', 'sub_category_id', 'anonymous', 'hidden', 'deleted', 'banned', 'trusted', 'remake', 'complete'], unique=False)
|
||||
|
||||
op.execute('UPDATE sukebei_torrents SET anonymous = TRUE WHERE flags & 1 IS TRUE;')
|
||||
op.execute('UPDATE sukebei_torrents SET hidden = TRUE WHERE flags & 2 IS TRUE;')
|
||||
|
@ -88,7 +90,7 @@ def upgrade():
|
|||
op.execute('UPDATE sukebei_torrents SET banned = TRUE WHERE flags & 64 IS TRUE;')
|
||||
op.execute('UPDATE sukebei_torrents SET comment_locked = TRUE WHERE flags & 128 IS TRUE;')
|
||||
|
||||
op.drop_column('sukebei_torrents', 'flags')
|
||||
#op.drop_column('sukebei_torrents', 'flags')
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
|
|
@ -84,7 +84,7 @@ class TorrentBase(DeclarativeHelperBase):
|
|||
@declarative.declared_attr
|
||||
def uploader_id(cls):
|
||||
# Even though this is same for both tables, declarative requires this
|
||||
return db.Column(db.Integer, db.ForeignKey('users.id'), nullable=True)
|
||||
return db.Column(db.Integer, db.ForeignKey('users.id'), nullable=True, index=True)
|
||||
|
||||
uploader_ip = db.Column(db.Binary(length=16), default=None, nullable=True)
|
||||
has_torrent = db.Column(db.Boolean, nullable=False, default=False)
|
||||
|
@ -95,6 +95,15 @@ class TorrentBase(DeclarativeHelperBase):
|
|||
updated_time = db.Column(db.DateTime(timezone=False), default=datetime.utcnow,
|
||||
onupdate=datetime.utcnow, nullable=False)
|
||||
|
||||
anonymous = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
hidden = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
deleted = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
banned = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
trusted = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
remake = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
complete = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
comment_locked = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
|
||||
@declarative.declared_attr
|
||||
def main_category_id(cls):
|
||||
fk = db.ForeignKey(cls._table_prefix('main_categories.id'))
|
||||
|
@ -110,6 +119,9 @@ class TorrentBase(DeclarativeHelperBase):
|
|||
@declarative.declared_attr
|
||||
def __table_args__(cls):
|
||||
return (
|
||||
Index('ix_' + cls._table_prefix('super'), 'id', 'uploader_id',
|
||||
'main_category_id', 'sub_category_id',
|
||||
'anonymous', 'hidden', 'deleted', 'banned', 'trusted', 'remake', 'complete'),
|
||||
ForeignKeyConstraint(
|
||||
['main_category_id', 'sub_category_id'],
|
||||
[cls._table_prefix('sub_categories.main_category_id'),
|
||||
|
@ -213,17 +225,6 @@ class TorrentBase(DeclarativeHelperBase):
|
|||
if self.uploader_ip:
|
||||
return str(ip_address(self.uploader_ip))
|
||||
|
||||
# Flag properties below
|
||||
|
||||
anonymous = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
hidden = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
deleted = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
banned = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
trusted = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
remake = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
complete = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
comment_locked = db.Column(db.Boolean, nullable=False, default=False, index=True)
|
||||
|
||||
# Class methods
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -399,11 +399,16 @@ def search_db(term='', user=None, sort='id', order='desc', category='0_0',
|
|||
item, models.TorrentNameSearch, FullTextMode.NATURAL))
|
||||
|
||||
query, count_query = qpc.items
|
||||
super_index = 'ix_' + models.Torrent._table_prefix('super')
|
||||
# Sort and order
|
||||
if sort_column.class_ != models.Torrent:
|
||||
index_name = _get_index_name(sort_column)
|
||||
query = query.join(sort_column.class_)
|
||||
query = query.with_hint(sort_column.class_, 'USE INDEX ({0})'.format(index_name))
|
||||
else:
|
||||
query = query.with_hint(models.Torrent, 'USE INDEX ({0})'.format(super_index))
|
||||
|
||||
count_query = count_query.with_hint(models.Torrent, 'USE INDEX ({0})'.format(super_index))
|
||||
|
||||
query = query.order_by(getattr(sort_column, order)())
|
||||
|
||||
|
|
Loading…
Reference in a new issue