diff --git a/app/main/routes.py b/app/main/routes.py index a4d8607c..d238593b 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -60,6 +60,7 @@ def home_page(type, sort): return return_304(current_etag) page = request.args.get('page', 1, type=int) + low_bandwidth = request.cookies.get('low_bandwidth', '0') == '1' if current_user.is_anonymous: flash(_('Create an account to tailor this feed to your interests.')) @@ -110,7 +111,7 @@ def home_page(type, sort): posts = posts.order_by(desc(Post.last_active)) # Pagination - posts = posts.paginate(page=page, per_page=100, error_out=False) + posts = posts.paginate(page=page, per_page=100 if current_user.is_authenticated and not low_bandwidth else 50, error_out=False) if type == 'home': next_url = url_for('main.index', page=posts.next_num, sort=sort) if posts.has_next else None prev_url = url_for('main.index', page=posts.prev_num, sort=sort) if posts.has_prev and page != 1 else None @@ -125,7 +126,7 @@ def home_page(type, sort): return render_template('index.html', posts=posts, active_communities=active_communities, show_post_community=True, POST_TYPE_IMAGE=POST_TYPE_IMAGE, POST_TYPE_LINK=POST_TYPE_LINK, - low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1', + low_bandwidth=low_bandwidth, SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, etag=f"{type}_{sort}_{hash(str(g.site.last_active))}", next_url=next_url, prev_url=prev_url, rss_feed=f"https://{current_app.config['SERVER_NAME']}/feed", diff --git a/app/templates/post/post.html b/app/templates/post/post.html index 8ed1a5f9..43e88033 100644 --- a/app/templates/post/post.html +++ b/app/templates/post/post.html @@ -103,7 +103,7 @@
{% if post.comments_enabled %} - reply + reply {% endif %}
{% with comment=comment['comment'] %} @@ -120,7 +120,7 @@ {% if current_user.is_authenticated and current_user.verified and current_user.id == comment['comment'].author.id %} {% include "post/_reply_notification_toggle.html" %} {% endif %} - +
{% if comment['replies'] %} {% if comment['comment'].depth <= THREAD_CUTOFF_DEPTH %} diff --git a/app/utils.py b/app/utils.py index 89b1d64d..f20d3893 100644 --- a/app/utils.py +++ b/app/utils.py @@ -62,7 +62,8 @@ def return_304(etag, content_type=None): # Jinja: when a file was modified. Useful for cache-busting def getmtime(filename): - return os.path.getmtime('static/' + filename) + if os.path.exists('static/' + filename): + return os.path.getmtime('static/' + filename) # do a GET request to a uri, return the result diff --git a/dev_notes.txt b/dev_notes.txt index abe4553a..30b56799 100644 --- a/dev_notes.txt +++ b/dev_notes.txt @@ -10,3 +10,9 @@ sudo systemctl restart celeryd or sudo service celeryd restart *** check for celery-related problems by looking in /var/log/celery *** +for profiling: +use +python profile_app.py +instead of +flask run + diff --git a/profile_app.py b/profile_app.py new file mode 100644 index 00000000..d1557e01 --- /dev/null +++ b/profile_app.py @@ -0,0 +1,41 @@ +#!flask/bin/python +import os + +from flask import session, g, json +from flask_babel import get_locale +from werkzeug.middleware.profiler import ProfilerMiddleware +from app import create_app, db, cli +from app.models import Site +from app.utils import gibberish, shorten_number, community_membership, getmtime, digits, user_access, ap_datetime, \ + can_create, can_upvote, can_downvote, current_theme, shorten_string, shorten_url + +app = create_app() + +with app.app_context(): + app.jinja_env.globals['getmtime'] = getmtime + app.jinja_env.globals['len'] = len + app.jinja_env.globals['digits'] = digits + app.jinja_env.globals['str'] = str + app.jinja_env.globals['shorten_number'] = shorten_number + app.jinja_env.globals['community_membership'] = community_membership + app.jinja_env.globals['json_loads'] = json.loads + app.jinja_env.globals['user_access'] = user_access + app.jinja_env.globals['ap_datetime'] = ap_datetime + app.jinja_env.globals['can_create'] = can_create + app.jinja_env.globals['can_upvote'] = can_upvote + app.jinja_env.globals['can_downvote'] = can_downvote + app.jinja_env.globals['theme'] = current_theme + app.jinja_env.globals['file_exists'] = os.path.exists + app.jinja_env.filters['shorten'] = shorten_string + app.jinja_env.filters['shorten_url'] = shorten_url + app.config['PROFILE'] = True + app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30]) + app.run(debug = True, host='127.0.0.1') + + + +@app.before_request +def before_request(): + session['nonce'] = gibberish() + g.locale = str(get_locale()) + g.site = Site.query.get(1) \ No newline at end of file