Also report note URL for revision check
This commit is contained in:
parent
a9d7f142e7
commit
5cde4ac06b
|
@ -94,6 +94,7 @@ def revisions_to_be_expired(cutoff: datetime) -> list[any]:
|
|||
"Users"."email",
|
||||
"Revisions"."id" as "revisionId",
|
||||
"Notes"."id" as "noteId",
|
||||
"Notes"."shortid" as "shortid",
|
||||
"Notes"."title"
|
||||
FROM "Revisions", "Notes", "Users"
|
||||
WHERE "Revisions"."createdAt" < $1
|
||||
|
@ -106,6 +107,7 @@ def revisions_to_be_expired(cutoff: datetime) -> list[any]:
|
|||
'email': row.email,
|
||||
'noteId': row.noteId,
|
||||
'revisionId': row.revisionId,
|
||||
'shortid': row.shortid,
|
||||
'title': row.title
|
||||
})
|
||||
return revisions
|
||||
|
@ -119,7 +121,7 @@ def check_notes_to_be_expired(age: timedelta, config: Config) -> None:
|
|||
print(f' {note["email"]} ({humanize.naturaldelta(age)}) {config.url}/{note["alias"]}: {note["title"]}')
|
||||
|
||||
|
||||
def check_revisions_to_be_expired(age: timedelta) -> None:
|
||||
def check_revisions_to_be_expired(age: timedelta, config: Config) -> None:
|
||||
cutoff = datetime.now(timezone.utc) - age
|
||||
print(f'Revisions to be deleted older than {cutoff} ({humanize.naturaldelta(age)}):')
|
||||
notes = {}
|
||||
|
@ -130,7 +132,8 @@ def check_revisions_to_be_expired(age: timedelta) -> None:
|
|||
notes[row['noteId']].append(row)
|
||||
for id, revisions in notes.items():
|
||||
email = revisions[0]['email']
|
||||
print(f' {revisions[0]["email"]}: {revisions[0]["title"]}')
|
||||
url = config.url + '/' + (revisions[0]["title"] if revisions[0]["title"] is not None else revisions[0]["shorturl"])
|
||||
print(f' {revisions[0]["email"]} {url}: {revisions[0]["title"]}')
|
||||
for rev in revisions:
|
||||
print(f' {humanize.naturaldelta(rev["age"])}: {rev["revisionId"]}')
|
||||
|
||||
|
@ -199,7 +202,7 @@ if __name__ == '__main__':
|
|||
|
||||
with pgsql.Connection((config.postgres_hostname, config.postgres_port), config.postgres_username, config.postgres_password) as db:
|
||||
if args.check:
|
||||
check_revisions_to_be_expired(revisions_delta)
|
||||
check_revisions_to_be_expired(revisions_delta, config)
|
||||
check_notes_to_be_expired(notes_delta, config)
|
||||
sys.exit(0)
|
||||
expire_old_revisions(revisions_delta)
|
||||
|
|
Loading…
Reference in a new issue