From 84ad979cd91ae54caf14a7b785a6b7d6509b7250 Mon Sep 17 00:00:00 2001 From: Brian Broll Date: Tue, 21 Jul 2020 16:49:10 -0500 Subject: [PATCH] Add beforeLibraryUpdates flag to updates. Closes #1788 --- src/common/utils.js | 13 +++++++++ .../panels/Sidebar/SidebarPanel.js | 28 +++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/common/utils.js b/src/common/utils.js index 00d4d6c32..47f4f31a5 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -147,6 +147,18 @@ } } + function partition(list, mapItemToIndex) { + const lists = []; + list.forEach(item => { + const index = +mapItemToIndex(item); + if (!lists[index]) { + lists[index] = []; + } + lists[index].push(item); + }); + return lists; + } + return { deepExtend, splitObj, @@ -156,5 +168,6 @@ defer, sleep, waitUntil, + partition, }; })); diff --git a/src/visualizers/panels/Sidebar/SidebarPanel.js b/src/visualizers/panels/Sidebar/SidebarPanel.js index b2e0d2034..1178f5f51 100644 --- a/src/visualizers/panels/Sidebar/SidebarPanel.js +++ b/src/visualizers/panels/Sidebar/SidebarPanel.js @@ -167,21 +167,39 @@ define([ }; SidebarPanel.prototype.applyUpdates = async function (updates) { - const seedUpdates = updates.filter(update => update.type === Updates.SEED); + const [seedUpdates, earlyMigrations, migrations] = Utils.partition( + updates, + update => { + if (update.type === Updates.SEED) { + return 0; + } + if (Updates.getUpdate(update.name).beforeLibraryUpdates) { + return 1; + } + return 2; + } + ); + + await this.applyMigrationUpdates(earlyMigrations); + + await Utils.sleep(1000); + for (let i = 0; i < seedUpdates.length; i++) { const {name, hash} = seedUpdates[i]; await Q.ninvoke(this._client, 'updateLibrary', name, hash); } await Utils.sleep(1000); + await this.applyMigrationUpdates(migrations); + }; + + SidebarPanel.prototype.applyMigrationUpdates = async function (updates) { const pluginId = 'ApplyUpdates'; - const migrations = updates - .filter(update => update.type === Updates.MIGRATION) - .map(update => update.name); + const names = updates.map(update => update.name); const context = this._client.getCurrentPluginContext(pluginId); context.pluginConfig = { - updates: migrations + updates: names, }; await Q.ninvoke(this._client, 'runServerPlugin', pluginId, context);