Created
January 29, 2012 18:16
-
-
Save gazpachoking/1699957 to your computer and use it in GitHub Desktop.
Adding some indexes to FlexGet db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: flexget/utils/simple_persistence.py | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- flexget/utils/simple_persistence.py (revision 2688) | |
+++ flexget/utils/simple_persistence.py (revision ) | |
@@ -10,7 +10,7 @@ | |
import logging | |
from datetime import datetime | |
import pickle | |
-from sqlalchemy import Column, Integer, String, DateTime, PickleType, select | |
+from sqlalchemy import Column, Integer, String, DateTime, PickleType, select, Index | |
from UserDict import DictMixin | |
from flexget import schema | |
from flexget.manager import Session | |
@@ -18,7 +18,7 @@ | |
from flexget.utils.sqlalchemy_utils import table_schema | |
log = logging.getLogger('util.simple_persistence') | |
-Base = schema.versioned_base('simple_persistence', 1) | |
+Base = schema.versioned_base('simple_persistence', 2) | |
@schema.upgrade('simple_persistence') | |
@@ -36,6 +36,11 @@ | |
log.warning('Couldn\'t load %s:%s removing from db: %s' % (row['plugin'], row['key'], e)) | |
session.execute(table.delete().where(table.c.id == row['id'])) | |
ver = 1 | |
+ if ver == 1: | |
+ table = table_schema('simple_persistence', session) | |
+ log.info('Creating index on simple_persistence table.') | |
+ Index('simple_persistence_feed_plugin_key', table.c.feed, table.c.plugin, table.c.key).create(bind=session.bind) | |
+ ver = 2 | |
return ver | |
@@ -60,6 +65,8 @@ | |
def __repr__(self): | |
return "<SimpleKeyValue('%s','%s','%s')>" % (self.feed, self.key, self.value) | |
+ | |
+Index('simple_persistence_feed_plugin_key', SimpleKeyValue.feed, SimpleKeyValue.plugin, SimpleKeyValue.key) | |
class SimplePersistence(DictMixin): | |
Index: flexget/plugins/filter/seen.py | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- flexget/plugins/filter/seen.py (revision 2688) | |
+++ flexget/plugins/filter/seen.py (revision ) | |
@@ -10,7 +10,7 @@ | |
import logging | |
from datetime import datetime, timedelta | |
-from sqlalchemy import Column, Integer, String, DateTime, Unicode, asc, or_, select, update | |
+from sqlalchemy import Column, Integer, String, DateTime, Unicode, asc, or_, select, update, Index | |
from sqlalchemy.schema import ForeignKey | |
from sqlalchemy.orm import relation | |
from flexget.manager import Session | |
@@ -21,7 +21,7 @@ | |
from flexget.utils.imdb import extract_id | |
log = logging.getLogger('seen') | |
-Base = schema.versioned_base('seen', 1) | |
+Base = schema.versioned_base('seen', 2) | |
@schema.upgrade('seen') | |
@@ -33,6 +33,11 @@ | |
new_values = {'field': 'imdb_id', 'value': extract_id(row['value'])} | |
session.execute(update(field_table, field_table.c.id == row['id'], new_values)) | |
ver = 1 | |
+ if ver == 1: | |
+ field_table = table_schema('seen_field', session) | |
+ log.info('Adding index to seen_field table.') | |
+ Index('seen_field_seen_entry_id', field_table.c.seen_entry_id).create(bind=session.bind) | |
+ ver = 2 | |
return ver | |
@@ -63,7 +68,7 @@ | |
__tablename__ = 'seen_field' | |
id = Column(Integer, primary_key=True) | |
- seen_entry_id = Column(Integer, ForeignKey('seen_entry.id'), nullable=False) | |
+ seen_entry_id = Column(Integer, ForeignKey('seen_entry.id'), nullable=False, index=True) | |
field = Column(Unicode) | |
value = Column(Unicode, index=True) | |
added = Column(DateTime) | |
Index: flexget/plugins/output/dump.py | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- flexget/plugins/output/dump.py (revision 2688) | |
+++ flexget/plugins/output/dump.py (revision ) | |
@@ -1,4 +1,4 @@ | |
-from flexget.plugin import register_plugin, register_parser_option | |
+from flexget.plugin import register_plugin, register_parser_option, priority | |
import logging | |
from flexget.utils.tools import console | |
@@ -62,6 +62,7 @@ | |
else: | |
OutputDump.params = True | |
+ @priority(0) | |
def on_feed_output(self, feed): | |
if not 'dump' in feed.config and not OutputDump.params: | |
return | |
Index: flexget/plugins/input/backlog.py | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- flexget/plugins/input/backlog.py (revision 2688) | |
+++ flexget/plugins/input/backlog.py (revision ) | |
@@ -1,7 +1,7 @@ | |
import logging | |
import pickle | |
from datetime import datetime | |
-from sqlalchemy import Column, Integer, String, DateTime, PickleType | |
+from sqlalchemy import Column, Integer, String, DateTime, PickleType, Index | |
from flexget import schema | |
from flexget.entry import Entry | |
from flexget.manager import Session | |
@@ -11,7 +11,7 @@ | |
from flexget.utils.tools import parse_timedelta | |
log = logging.getLogger('backlog') | |
-Base = schema.versioned_base('backlog', 0) | |
+Base = schema.versioned_base('backlog', 1) | |
@schema.upgrade('backlog') | |
@@ -27,6 +27,11 @@ | |
log.info('Backlog table contains unloadable data, clearing old data.') | |
session.execute(backlog_table.delete()) | |
ver = 0 | |
+ if ver == 0: | |
+ backlog_table = table_schema('backlog', session) | |
+ log.info('Creating index on backlog table.') | |
+ Index('backlog_feed_expire', backlog_table.c.feed, backlog_table.c.expire).create(bind=session.bind) | |
+ ver = 1 | |
return ver | |
@@ -43,6 +48,8 @@ | |
def __repr__(self): | |
return '<BacklogEntry(title=%s)>' % (self.title) | |
+ | |
+Index('backlog_feed_expire', BacklogEntry.feed, BacklogEntry.expire) | |
class InputBacklog(object): | |
Index: flexget/plugins/filter/series.py | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- flexget/plugins/filter/series.py (revision 2688) | |
+++ flexget/plugins/filter/series.py (revision ) | |
@@ -17,7 +17,7 @@ | |
from flexget.plugin import (register_plugin, register_parser_option, get_plugin_by_name, get_plugin_keywords, | |
PluginWarning, DependencyError, priority) | |
-SCHEMA_VER = 2 | |
+SCHEMA_VER = 3 | |
log = logging.getLogger('series') | |
Base = schema.versioned_base('series', SCHEMA_VER) | |
@@ -59,6 +59,11 @@ | |
log.info('Adding `identified_by` column to series table.') | |
table_add_column('series', 'identified_by', String, session) | |
ver = 2 | |
+ if ver == 2: | |
+ release_table = table_schema('episode_releases', session) | |
+ log.info('Creating index on episode_releases table.') | |
+ Index('episode_releases_episode_id', release_table.c.episode_id).create(bind=session.bind) | |
+ ver = 3 | |
return ver | |
@@ -162,7 +167,7 @@ | |
__tablename__ = 'episode_releases' | |
id = Column(Integer, primary_key=True) | |
- episode_id = Column(Integer, ForeignKey('series_episodes.id'), nullable=False) | |
+ episode_id = Column(Integer, ForeignKey('series_episodes.id'), nullable=False, index=True) | |
_quality = Column('quality', String) | |
quality = quality_property('_quality') | |
downloaded = Column(Boolean, default=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment