mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
(core) Prevent logging pointless errors about attachments and data size on shutdown
Summary: As suggested in https://grist.slack.com/archives/CR8HZ4P9V/p1652365399661569?thread_ts=1652364998.893169&cid=CR8HZ4P9V, check if DocStorage is initialized before trying to use it when shutting down, to avoid noisy logging of errors about removing attachments and updating data size. Test Plan: Tested manually that errors early in loadDoc caused logging of errors about attachments/data size before the changed, but not after. Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D3522
This commit is contained in:
parent
29fb3360b6
commit
f1df6c0a46
@ -485,24 +485,28 @@ export class ActiveDoc extends EventEmitter {
|
|||||||
// We'll defer syncing usage until everything is calculated.
|
// We'll defer syncing usage until everything is calculated.
|
||||||
const usageOptions = {syncUsageToDatabase: false, broadcastUsageToClients: false};
|
const usageOptions = {syncUsageToDatabase: false, broadcastUsageToClients: false};
|
||||||
|
|
||||||
// Remove expired attachments, i.e. attachments that were soft deleted a while ago. This
|
// This cleanup requires docStorage, which may have failed to start up.
|
||||||
// needs to happen periodically, and doing it here means we can guarantee that it happens
|
// We don't want to log pointless errors in that case.
|
||||||
// even if the doc is only ever opened briefly, without having to slow down startup.
|
if (this.docStorage.isInitialized()) {
|
||||||
const removeAttachmentsPromise = this.removeUnusedAttachments(true, usageOptions);
|
// Remove expired attachments, i.e. attachments that were soft deleted a while ago. This
|
||||||
|
// needs to happen periodically, and doing it here means we can guarantee that it happens
|
||||||
|
// even if the doc is only ever opened briefly, without having to slow down startup.
|
||||||
|
const removeAttachmentsPromise = this.removeUnusedAttachments(true, usageOptions);
|
||||||
|
|
||||||
// Update data size; we'll be syncing both it and attachments size to the database soon.
|
// Update data size; we'll be syncing both it and attachments size to the database soon.
|
||||||
const updateDataSizePromise = this._updateDataSize(usageOptions);
|
const updateDataSizePromise = this._updateDataSize(usageOptions);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await removeAttachmentsPromise;
|
await removeAttachmentsPromise;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this._log.error(docSession, "Failed to remove expired attachments", e);
|
this._log.error(docSession, "Failed to remove expired attachments", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await updateDataSizePromise;
|
await updateDataSizePromise;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this._log.error(docSession, "Failed to update data size", e);
|
this._log.error(docSession, "Failed to update data size", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._syncDocUsageToDatabase(true);
|
this._syncDocUsageToDatabase(true);
|
||||||
|
@ -674,6 +674,10 @@ export class DocStorage implements ISQLiteDB, OnDemandStorage {
|
|||||||
// Note that we don't call _updateMetadata() as there are no metadata tables yet anyway.
|
// Note that we don't call _updateMetadata() as there are no metadata tables yet anyway.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public isInitialized(): boolean {
|
||||||
|
return Boolean(this._db);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the database with proper settings.
|
* Initializes the database with proper settings.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user