aboutsummaryrefslogtreecommitdiffstats
path: root/youtube
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2019-06-08 02:35:21 -0700
committerJames Taylor <user234683@users.noreply.github.com>2019-06-08 02:35:21 -0700
commitf5c76462d722d45645029754b4fc85252cf8212e (patch)
tree36532c1a2e48f81744d37cb3bb03e2a7fd504c58 /youtube
parentc8be729e6ba706654849ed39e6238aebf85f1f36 (diff)
downloadyt-local-f5c76462d722d45645029754b4fc85252cf8212e.tar.lz
yt-local-f5c76462d722d45645029754b4fc85252cf8212e.tar.xz
yt-local-f5c76462d722d45645029754b4fc85252cf8212e.zip
Don't spam database with opening and closing when getting tags for many channels
Diffstat (limited to 'youtube')
-rw-r--r--youtube/subscriptions.py30
1 files changed, 15 insertions, 15 deletions
diff --git a/youtube/subscriptions.py b/youtube/subscriptions.py
index a3af40f..ff74d94 100644
--- a/youtube/subscriptions.py
+++ b/youtube/subscriptions.py
@@ -125,14 +125,12 @@ def _remove_tags(channel_ids, tags):
-def _get_tags(channel_id):
- with open_database() as connection:
- with connection as cursor:
- return [row[0] for row in cursor.execute('''SELECT tag
- FROM tag_associations
- WHERE sql_channel_id = (
- SELECT id FROM subscribed_channels WHERE yt_channel_id = ?
- )''', (channel_id,))]
+def _get_tags(cursor, channel_id):
+ return [row[0] for row in cursor.execute('''SELECT tag
+ FROM tag_associations
+ WHERE sql_channel_id = (
+ SELECT id FROM subscribed_channels WHERE yt_channel_id = ?
+ )''', (channel_id,))]
def _get_all_tags():
with open_database() as connection:
@@ -253,13 +251,15 @@ sub_list_item_template = Template('''
def get_subscription_manager_page(env, start_response):
sub_list_html = ''
- for channel_name, channel_id in _get_subscribed_channels():
- sub_list_html += sub_list_item_template.substitute(
- channel_url = util.URL_ORIGIN + '/channel/' + channel_id,
- channel_name = html.escape(channel_name),
- channel_id = channel_id,
- tags = ', '.join(_get_tags(channel_id)),
- )
+ with open_database() as connection:
+ with connection as cursor:
+ for channel_name, channel_id in _get_subscribed_channels():
+ sub_list_html += sub_list_item_template.substitute(
+ channel_url = util.URL_ORIGIN + '/channel/' + channel_id,
+ channel_name = html.escape(channel_name),
+ channel_id = channel_id,
+ tags = ', '.join(_get_tags(cursor, channel_id)),
+ )