mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Remove expired attachments every hour and on shutdown
Summary: Call ActiveDoc.removeUnusedAttachments every hour using setInterval, and in ActiveDoc.shutdown (which also clears said interval). Unrelated: small fix to my webhooks code which was creating a redis client on shutdown just to quit it. Test Plan: Tweaked DocApi test to remove expired attachments by force-reloading the doc, so that it removes them during shutdown. Extracted a new testing endpoint /verifyFiles to support this test (previously running that code only happened with `/removeUnused?verifyfiles=1`). Tested the setInterval part manually. Reviewers: paulfitz, dsagal Reviewed By: paulfitz Subscribers: dsagal Differential Revision: https://phab.getgrist.com/D3387
This commit is contained in:
@@ -1707,17 +1707,20 @@ function testDocApi() {
|
||||
assert.equal(resp.status, 200);
|
||||
await checkAttachmentIds([1, 2, 3]);
|
||||
|
||||
// Remove the expired attachment (1)
|
||||
// Remove the expired attachment (1) by force-reloading, so it removes it during shutdown.
|
||||
// It has a duplicate (3) that hasn't expired and thus isn't removed,
|
||||
// although they share the same fileIdent and row in _gristsys_Files.
|
||||
// So for now only the metadata is removed.
|
||||
resp = await axios.post(`${docUrl}/attachments/removeUnused?verifyfiles=1&expiredonly=1`, null, chimpy);
|
||||
resp = await axios.post(`${docUrl}/force-reload`, null, chimpy);
|
||||
assert.equal(resp.status, 200);
|
||||
await checkAttachmentIds([2, 3]);
|
||||
resp = await axios.post(`${docUrl}/attachments/verifyFiles`, null, chimpy);
|
||||
assert.equal(resp.status, 200);
|
||||
|
||||
// Remove the not expired attachments (2 and 3).
|
||||
// We didn't set a timeDeleted for 3, but it gets set automatically by updateUsedAttachments.
|
||||
resp = await axios.post(`${docUrl}/attachments/removeUnused?verifyfiles=1`, null, chimpy);
|
||||
assert.equal(resp.status, 200);
|
||||
await checkAttachmentIds([]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user