From 5677fd14e5bd074d2768cd0bb513d90ed0586fff Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Sun, 9 Nov 2025 11:49:10 +0100 Subject: [PATCH] fix: Fixed pins not saving proprely, b=closes #11217, c=tabs --- src/zen/tabs/ZenPinnedTabManager.mjs | 4 ---- src/zen/tabs/ZenPinnedTabsStorage.mjs | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/zen/tabs/ZenPinnedTabManager.mjs b/src/zen/tabs/ZenPinnedTabManager.mjs index eebfadf06..779f3566b 100644 --- a/src/zen/tabs/ZenPinnedTabManager.mjs +++ b/src/zen/tabs/ZenPinnedTabManager.mjs @@ -778,10 +778,6 @@ return; } const existingPin = this._pinsCache.find((p) => p.uuid === pin.uuid); - if (existingPin && existingPin === pin) { - // We want to avoid unnecessary writes - return; - } if (existingPin) { Object.assign(existingPin, pin); } else { diff --git a/src/zen/tabs/ZenPinnedTabsStorage.mjs b/src/zen/tabs/ZenPinnedTabsStorage.mjs index 425dbf2d1..bc11213f7 100644 --- a/src/zen/tabs/ZenPinnedTabsStorage.mjs +++ b/src/zen/tabs/ZenPinnedTabsStorage.mjs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. var ZenPinnedTabsStorage = { + _saveCache: [], + async init() { await this._ensureTable(); }, @@ -74,6 +76,22 @@ var ZenPinnedTabsStorage = { }, async savePin(pin, notifyObservers = true) { + // If we find the exact same pin in the cache, skip saving + const existingIndex = this._saveCache.findIndex((cachedPin) => cachedPin.uuid === pin.uuid); + if (existingIndex !== -1) { + const existingPin = this._saveCache[existingIndex]; + const isSame = Object.keys(pin).every((key) => pin[key] === existingPin[key]); + if (isSame) { + return; // No changes, skip saving + } else { + // Update the cached pin + this._saveCache[existingIndex] = pin; + } + } else { + // Add to cache + this._saveCache.push(pin); + } + const changedUUIDs = new Set(); await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.savePin', async (db) => { @@ -389,6 +407,11 @@ var ZenPinnedTabsStorage = { }, async removePin(uuid, notifyObservers = true) { + const cachedIndex = this._saveCache.findIndex((cachedPin) => cachedPin.uuid === uuid); + if (cachedIndex !== -1) { + this._saveCache.splice(cachedIndex, 1); + } + const changedUUIDs = [uuid]; await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.removePin', async (db) => {