Don't spam database with opening and closing when getting tags for many channels
This commit is contained in:
parent
c8be729e6b
commit
f5c76462d7
@ -125,9 +125,7 @@ def _remove_tags(channel_ids, tags):
|
||||
|
||||
|
||||
|
||||
def _get_tags(channel_id):
|
||||
with open_database() as connection:
|
||||
with connection as cursor:
|
||||
def _get_tags(cursor, channel_id):
|
||||
return [row[0] for row in cursor.execute('''SELECT tag
|
||||
FROM tag_associations
|
||||
WHERE sql_channel_id = (
|
||||
@ -253,12 +251,14 @@ sub_list_item_template = Template('''
|
||||
def get_subscription_manager_page(env, start_response):
|
||||
|
||||
sub_list_html = ''
|
||||
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(channel_id)),
|
||||
tags = ', '.join(_get_tags(cursor, channel_id)),
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user