mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-12-04 12:26:34 +00:00
fix: free unused journal.Reader instances (#158)
I'm a bit dumb and forgot to add code that frees journal.Reader instances from memory. Co-authored-by: nhnn <nhnn@disroot.org> Co-authored-by: Inex Code <inex.code@selfprivacy.org> Reviewed-on: https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api/pulls/158 Reviewed-by: Inex Code <inex.code@selfprivacy.org> Co-authored-by: nhnn <nhnn@noreply.git.selfprivacy.org> Co-committed-by: nhnn <nhnn@noreply.git.selfprivacy.org>
This commit is contained in:
parent
848befe3f1
commit
5aa1a378ef
|
@ -21,11 +21,17 @@ async def log_stream() -> AsyncGenerator[LogEntry, None]:
|
|||
|
||||
asyncio.get_event_loop().add_reader(j, lambda: asyncio.ensure_future(callback()))
|
||||
|
||||
try:
|
||||
while True:
|
||||
entry = await queue.get()
|
||||
try:
|
||||
yield LogEntry(entry)
|
||||
except Exception:
|
||||
asyncio.get_event_loop().remove_reader(j)
|
||||
j.close()
|
||||
return
|
||||
queue.task_done()
|
||||
except asyncio.CancelledError:
|
||||
asyncio.get_event_loop().remove_reader(j)
|
||||
j.close()
|
||||
return
|
||||
|
|
|
@ -42,6 +42,8 @@ def get_paginated_logs(
|
|||
events = get_events_from_journal(j, limit, lambda j: j.get_previous())
|
||||
events.reverse()
|
||||
|
||||
j.close()
|
||||
|
||||
return events
|
||||
elif up_cursor is None and down_cursor is not None:
|
||||
j.seek_cursor(down_cursor)
|
||||
|
@ -50,6 +52,8 @@ def get_paginated_logs(
|
|||
events = get_events_from_journal(j, limit, lambda j: j.get_previous())
|
||||
events.reverse()
|
||||
|
||||
j.close()
|
||||
|
||||
return events
|
||||
elif up_cursor is not None and down_cursor is None:
|
||||
j.seek_cursor(up_cursor)
|
||||
|
@ -57,8 +61,12 @@ def get_paginated_logs(
|
|||
|
||||
events = get_events_from_journal(j, limit, lambda j: j.get_next())
|
||||
|
||||
j.close()
|
||||
|
||||
return events
|
||||
else:
|
||||
j.close()
|
||||
|
||||
raise NotImplementedError(
|
||||
"Pagination by both up_cursor and down_cursor is not implemented"
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue