From 33f6a95ee7172be673faeae13c97fd42c56ea9b8 Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Sat, 12 Oct 2024 10:00:14 +0000 Subject: [PATCH] Bug 1866402 - Update the cached value in PersistOp::DoDirectoryWork only when the value changed in the metadata file; r=dom-storage-reviewers,jari Currently, we call QuotaManager::PersistOrigin even when the origin was already persisted. QuotaManager::PersistOrigin won't try to update the value again, but it will have to do a hash lookup. We can easilly avoid this by calling QuotaManager::PersistOrigin only when the value changed in the metadata file. Differential Revision: https://phabricator.services.mozilla.com/D198668 --- dom/quota/OriginOperations.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dom/quota/OriginOperations.cpp b/dom/quota/OriginOperations.cpp index cb38ed710cb44..e2909dac07ffc 100644 --- a/dom/quota/OriginOperations.cpp +++ b/dom/quota/OriginOperations.cpp @@ -3151,12 +3151,14 @@ nsresult PersistOp::DoDirectoryWork(QuotaManager& aQuotaManager) { // Set the persisted flag to true. QM_TRY(MOZ_TO_RESULT(stream->WriteBoolean(true))); - } - // Directory metadata has been successfully updated. - // Update OriginInfo too if temporary storage was already initialized. - if (aQuotaManager.IsTemporaryStorageInitializedInternal()) { - aQuotaManager.PersistOrigin(originMetadata); + QM_TRY(MOZ_TO_RESULT(stream->Close())); + + // Directory metadata has been successfully updated. + // Update OriginInfo too if temporary storage was already initialized. + if (aQuotaManager.IsTemporaryStorageInitializedInternal()) { + aQuotaManager.PersistOrigin(originMetadata); + } } }