mirror of
https://github.com/zen-browser/components.git
synced 2025-07-09 00:15:30 +02:00
feat: Improve workspace ordering and changes tracking
This commit introduces improvements to workspace ordering and change tracking in the Zen Workspaces system: - **Workspace Ordering:** - Uses `REAL` data type for `position` in `zen_workspaces` table, allowing for more precise and efficient ordering. - Introduces a new `updateWorkspaceOrder` method to update workspace positions. - Reorders workspaces with large increments to avoid frequent reordering, ensuring consistent ordering after changes. - Implements a mechanism to check for necessary reordering after position updates and reorder all workspaces if required. - **Changes Tracking:** - Tracks changes to workspaces by inserting a record in `zen_workspaces_changes` for each modified workspace. - Adds an index on `uuid` column in `zen_workspaces_changes` table for faster querying. - Updates `getLastChangeTimestamp` method to return the last change timestamp from the changes tracking table, providing accurate timestamp for changes. These changes optimize workspace management, improve accuracy of ordering, and enhance the performance of change tracking.
This commit is contained in:
parent
24d7af3da0
commit
8ca8157e61
2 changed files with 137 additions and 106 deletions
|
@ -30,15 +30,19 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
|||
Services.obs.addObserver(this, "weave:engine:sync:finish");
|
||||
}
|
||||
|
||||
observe(subject, topic, data) {
|
||||
async observe(subject, topic, data) {
|
||||
if (topic === "weave:engine:sync:finish" && data === "workspaces") {
|
||||
this._workspaceCache = null; // Clear cache to fetch fresh data
|
||||
this.updateWorkspaceStrip();
|
||||
}
|
||||
}
|
||||
try {
|
||||
const lastChangeTimestamp = await ZenWorkspacesStorage.getLastChangeTimestamp();
|
||||
|
||||
updateWorkspaceStrip() {
|
||||
this._propagateWorkspaceData().catch(console.error);
|
||||
if (!this._workspaceCache || !this._workspaceCache.lastChangeTimestamp || lastChangeTimestamp > this._workspaceCache.lastChangeTimestamp) {
|
||||
this._workspaceCache = null;
|
||||
await this._propagateWorkspaceData();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error updating workspaces after sync:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get shouldHaveWorkspaces() {
|
||||
|
@ -72,7 +76,16 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
|||
}
|
||||
|
||||
async _workspaces() {
|
||||
this._workspaceCache = { workspaces: await ZenWorkspacesStorage.getWorkspaces() };
|
||||
if (this._workspaceCache) {
|
||||
return this._workspaceCache;
|
||||
}
|
||||
|
||||
const [workspaces, lastChangeTimestamp] = await Promise.all([
|
||||
ZenWorkspacesStorage.getWorkspaces(),
|
||||
ZenWorkspacesStorage.getLastChangeTimestamp()
|
||||
]);
|
||||
|
||||
this._workspaceCache = { workspaces, lastChangeTimestamp };
|
||||
// Get the active workspace ID from preferences
|
||||
const activeWorkspaceId = Services.prefs.getStringPref('zen.workspaces.active', '');
|
||||
|
||||
|
@ -831,6 +844,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
|||
delete this._lastSelectedWorkspaceTabs[previousWorkspaceID];
|
||||
}
|
||||
}
|
||||
this._workspaceCache = null;
|
||||
const workspaces = await this._workspaces();
|
||||
await this.changeWorkspace(workspaces.workspaces.find((workspace) => workspace.uuid === workspaceID));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue