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",
|
"Users"."email",
|
||||||
"Revisions"."id" as "revisionId",
|
"Revisions"."id" as "revisionId",
|
||||||
"Notes"."id" as "noteId",
|
"Notes"."id" as "noteId",
|
||||||
|
"Notes"."shortid" as "shortid",
|
||||||
"Notes"."title"
|
"Notes"."title"
|
||||||
FROM "Revisions", "Notes", "Users"
|
FROM "Revisions", "Notes", "Users"
|
||||||
WHERE "Revisions"."createdAt" < $1
|
WHERE "Revisions"."createdAt" < $1
|
||||||
|
@ -106,6 +107,7 @@ def revisions_to_be_expired(cutoff: datetime) -> list[any]:
|
||||||
'email': row.email,
|
'email': row.email,
|
||||||
'noteId': row.noteId,
|
'noteId': row.noteId,
|
||||||
'revisionId': row.revisionId,
|
'revisionId': row.revisionId,
|
||||||
|
'shortid': row.shortid,
|
||||||
'title': row.title
|
'title': row.title
|
||||||
})
|
})
|
||||||
return revisions
|
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"]}')
|
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
|
cutoff = datetime.now(timezone.utc) - age
|
||||||
print(f'Revisions to be deleted older than {cutoff} ({humanize.naturaldelta(age)}):')
|
print(f'Revisions to be deleted older than {cutoff} ({humanize.naturaldelta(age)}):')
|
||||||
notes = {}
|
notes = {}
|
||||||
|
@ -130,7 +132,8 @@ def check_revisions_to_be_expired(age: timedelta) -> None:
|
||||||
notes[row['noteId']].append(row)
|
notes[row['noteId']].append(row)
|
||||||
for id, revisions in notes.items():
|
for id, revisions in notes.items():
|
||||||
email = revisions[0]['email']
|
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:
|
for rev in revisions:
|
||||||
print(f' {humanize.naturaldelta(rev["age"])}: {rev["revisionId"]}')
|
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:
|
with pgsql.Connection((config.postgres_hostname, config.postgres_port), config.postgres_username, config.postgres_password) as db:
|
||||||
if args.check:
|
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)
|
check_notes_to_be_expired(notes_delta, config)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
expire_old_revisions(revisions_delta)
|
expire_old_revisions(revisions_delta)
|
||||||
|
|
Loading…
Reference in a new issue