subqueryload to dramatically reduce the number of queries required

This commit is contained in:
Kyle Mahan 2015-03-17 21:03:45 -07:00
parent 17da903db7
commit a4113c9416
2 changed files with 11 additions and 5 deletions

View file

@ -152,7 +152,8 @@ def check_push_subscription(session, feed, response):
hub = response.links.get('hub', {}).get('url')
topic = response.links.get('self', {}).get('url')
logger.debug('link headers. links=%s, hub=%s, topic=%s', response.links, hub, topic)
logger.debug('link headers. links=%s, hub=%s, topic=%s',
response.links, hub, topic)
if not hub or not topic:
# try to find link rel elements
if feed.type == 'html':

View file

@ -13,6 +13,7 @@ import requests
import re
import urllib
import cgi
import sqlalchemy
views = flask.Blueprint('views', __name__)
@ -26,10 +27,14 @@ def index():
if flask_login.current_user.is_authenticated():
per_page = flask.current_app.config.get('PER_PAGE', 30)
offset = (page - 1) * per_page
entry_query = Entry.query\
.join(Entry.feed)\
.join(Feed.users)\
.filter(User.id == flask_login.current_user.id)
entry_query = Entry.query
entry_query = entry_query\
.options(sqlalchemy.orm.subqueryload(Entry.feed),
sqlalchemy.orm.subqueryload(Entry.reply_context))\
.join(Entry.feed)\
.join(Feed.users)\
.filter(User.id == flask_login.current_user.id)
if 'feed' in flask.request.args:
feed_hex = flask.request.args.get('feed').encode()