Repository navigation
Conversation
adds scripts/remove-ghost-papers.mjs, run with npm run ghost-papers. it sends a HEAD request to the file_url of every record in papers and admins, the same check the viewer does, and lists the ones that answer 404. anything else (403, 5xx, timeouts, no url) is left alone it is a dry run unless --delete is passed. with --delete it saves the full records to ghost-papers-<time>.json first, then deletes them, and only if their file_url has not changed since the check. it refuses to delete when more than half the files are missing, since a moved or renamed bucket also answers 404 refs CodeChefVIT#545
|
Hi @Dx-Alz-xD , ran a dry run on a staging copy (1,913 papers), found 37 real 404s, nice! Two things: the papers collection name is hardcoded (this DB uses paper), so a --collection option would help; and one record has a malformed URL (a Cloudinary link appended to the GCS path) that 404s even though the Cloudinary file exists, so it would get deleted wrongly. Maybe list malformed URLs separately instead of treating them as missing? Thanks! |
the script looked in papers, but mongoose treats "paper" as uncountable, so the Paper model's collection is paper. it now checks paper and admins by default, and --collection <name>, which can be given more than once, picks other collections. it stops and lists the database's collections when one it was given does not exist, instead of checking an empty one a file_url with a second link inside it, like a cloudinary url appended to the gcs path, answers 404 even when the file exists. those are now listed on their own as malformed and are never deleted
hi thanks for running it on staging! both are in 93cc0dc the default was wrong from the start: mongoose treats "paper" as uncountable, so the Paper model's collection is paper, not papers. it now checks paper and admins by default. --collection , which can be given more than once, picks others. if a collection it was given doesn't exist, it stops and lists the ones that do, instead of quietly checking an empty one |
closes #545
adds scripts/remove-ghost-papers.mjs for removing the records whose pdf no longer exists in the bucket
usage, with MONGODB_URI in .env:
how it decides
safety
tested against an in-memory mongodb and a local file server: the dry run changed nothing, --delete removed exactly the 404 records from both collections and kept the 403/500/unreachable/no-url ones, the backup had the full records, a second run found nothing, and the more-than-half guard refused with all files missing. also checked that storage.googleapis.com answers 404 for a missing object in a public bucket
notes