Skip to content

Commit

Permalink
Only filter out already-present logs if they are up-to-date
Browse files Browse the repository at this point in the history
Logs may be updated. The log index includes the time the log was last
updated in its response. Using it, we can re-parse logs which have been
updated since we last imported them. To do this, we add an optional second
argument to the logid iterator. Then, in filter_logs, we also yield updated
logs.

Closes: #30
Signed-off-by: Sean Anderson <[email protected]>
  • Loading branch information
Forty-Bot committed Aug 27, 2021
1 parent 0a2f7a6 commit 8fb8c59
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def fetch_players_logids(s, players=None, since=0, count=None, offset=0, limit=1

for log in log_list['logs']:
if log['date'] >= since:
yield log['id']
yield log['id'], log['date']
else:
# Don't fetch any more pages
count = fetched
Expand Down
17 changes: 14 additions & 3 deletions import.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,21 @@ def filter_logids(c, logids):
"""

for logid in logids:
try:
time = logid[1]
logid = logid[0]
except TypeError:
time = None

cur = c.cursor()
cur.execute("SELECT 1 FROM public.log WHERE logid=%s", (logid,))
for _ in cur:
break
cur.execute("""SELECT
time < %s
FROM public.log
WHERE logid = %s""", (time, logid))

for row in cur:
if row[0]:
yield logid
else:
yield logid

Expand Down

0 comments on commit 8fb8c59

Please sign in to comment.