Skip to content

Commit

Permalink
In /entries, don't collect entries into a list (keep it a generator).
Browse files Browse the repository at this point in the history
For #269.
  • Loading branch information
lemon24 committed Jan 15, 2022
1 parent e363a08 commit 16486d1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Version 2.8
Unreleased

* In the web application, show maxrss when debug is enabled. (:issue:`269`)
* In the web application, decrease memory usage of the entries page
when there are a lot of entries
(e.g. for 2.5k entries, the maxrss decreased from 115 MiB to 75 MiB),
at the expense of making "entries for feed" slightly slower.
(:issue:`269`)


Version 2.7
Expand Down
10 changes: 7 additions & 3 deletions src/reader/_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def get_reader():
g.reader = current_app.config['READER_CONFIG'].make_reader(
'app', plugin_loader=current_app.plugin_loader
)
# TODO: lowering g.reader._storage.chunk_size may reduce memory usage slightly
return g.reader


Expand Down Expand Up @@ -308,11 +309,14 @@ def get_entry_counts(**kwargs):
else:
raise

entries = list(entries)

entries_data = None
if feed_url:
entries_data = [e.id for e in entries]
# TODO: duplicated from entries = ... above
# TODO: can be made faster with a get_entry_ids() method
entries_data = [
e.id
for e in get_entries(**kwargs, limit=request.args.get('limit', type=int))
]

feed_entry_counts = None
if feed_url:
Expand Down
9 changes: 5 additions & 4 deletions src/reader/_app/templates/entries.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,9 @@
{% endif %}



{% set vars = namespace(entry_index=0) %}
{% for entry in entries %}
{% set vars.entry_index = loop.index %}

{% set feed = entry.feed %}
{% set content, _ = entry_content(entry, prefer_summary=False) %}
Expand Down Expand Up @@ -360,15 +361,15 @@ <h2><a href="{{ entry.link }}">


{% set limit = request.args.get('limit') | int %}
{% if limit -%}
{% if limit and vars.entry_index >= limit -%}
{%- set args = request.args.copy() -%}
{%- set _ = args.poplist('limit') -%}

<p>
showing only the first {{ limit }} entries;
showing only the first {{ vars.entry_index }} entries;
<a href='
{{- url_for('.entries', **args) -}}
{%- if entries %}#entry-{{ entries | length }}{% endif -%}
{%- if entries %}#entry-{{ vars.entry_index }}{% endif -%}
'>show all entries</a>
</p>

Expand Down

0 comments on commit 16486d1

Please sign in to comment.