From ab3971034d5583332fc539c1cf6f613cad254c82 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 16 Feb 2022 11:59:43 +0000 Subject: [PATCH 1/3] Quick fix for checklist API performance on default tenant in cloud. --- packages/backend-core/src/db/utils.js | 11 +++++++---- packages/worker/src/api/controllers/global/configs.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/backend-core/src/db/utils.js b/packages/backend-core/src/db/utils.js index f5ea2f8486..c4dcb8248b 100644 --- a/packages/backend-core/src/db/utils.js +++ b/packages/backend-core/src/db/utils.js @@ -179,8 +179,11 @@ exports.getStartEndKeyURL = (base, baseKey, tenantId = null) => { /** * if in production this will use the CouchDB _all_dbs call to retrieve a list of databases. If testing * when using Pouch it will use the pouchdb-all-dbs package. + * opts.efficient can be provided to make sure this call is always quick in a multi-tenant environment, + * but it may not be 100% accurate in full efficiency mode (some tenantless apps may be missed). */ -exports.getAllDbs = async () => { +exports.getAllDbs = async (opts = { efficient: false }) => { + const efficient = opts && opts.efficient // specifically for testing we use the pouch package for this if (env.isTest()) { return getCouch().allDbs() @@ -197,7 +200,7 @@ exports.getAllDbs = async () => { } let couchUrl = `${exports.getCouchUrl()}/_all_dbs` let tenantId = getTenantId() - if (!env.MULTI_TENANCY || tenantId === DEFAULT_TENANT_ID) { + if (!env.MULTI_TENANCY || (!efficient && tenantId === DEFAULT_TENANT_ID)) { // just get all DBs when: // - single tenancy // - default tenant @@ -225,13 +228,13 @@ exports.getAllDbs = async () => { * * @return {Promise} returns the app information document stored in each app database. */ -exports.getAllApps = async ({ dev, all, idsOnly } = {}) => { +exports.getAllApps = async ({ dev, all, idsOnly, efficient } = {}) => { const CouchDB = getCouch() let tenantId = getTenantId() if (!env.MULTI_TENANCY && !tenantId) { tenantId = DEFAULT_TENANT_ID } - let dbs = await exports.getAllDbs() + let dbs = await exports.getAllDbs({ efficient }) const appDbNames = dbs.filter(dbName => { const split = dbName.split(SEPARATOR) // it is an app, check the tenantId diff --git a/packages/worker/src/api/controllers/global/configs.js b/packages/worker/src/api/controllers/global/configs.js index 604e7d0e93..0d3c8903f2 100644 --- a/packages/worker/src/api/controllers/global/configs.js +++ b/packages/worker/src/api/controllers/global/configs.js @@ -251,7 +251,7 @@ exports.configChecklist = async function (ctx) { // TODO: Watch get started video // Apps exist - const apps = await getAllApps({ idsOnly: true }) + const apps = await getAllApps({ idsOnly: true, efficient: true }) // They have set up SMTP const smtpConfig = await getScopedFullConfig(db, { From 7bac5d5961125b3b2728c34632fd7b0fa2aff563 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 16 Feb 2022 12:36:24 +0000 Subject: [PATCH 2/3] Adding a check to make sure there is a tenant ID for the checklist call when looking up apps in multi-tenant envs. --- packages/worker/src/api/controllers/global/configs.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/worker/src/api/controllers/global/configs.js b/packages/worker/src/api/controllers/global/configs.js index 0d3c8903f2..2562dd4e2e 100644 --- a/packages/worker/src/api/controllers/global/configs.js +++ b/packages/worker/src/api/controllers/global/configs.js @@ -246,12 +246,16 @@ exports.destroy = async function (ctx) { exports.configChecklist = async function (ctx) { const db = getGlobalDB() + const tenantId = getTenantId() try { // TODO: Watch get started video - // Apps exist - const apps = await getAllApps({ idsOnly: true, efficient: true }) + let apps = [] + if (!env.MULTI_TENANCY || tenantId) { + // Apps exist + apps = await getAllApps({ idsOnly: true, efficient: true }) + } // They have set up SMTP const smtpConfig = await getScopedFullConfig(db, { From f872e29393bd96e98c31acf24036ff184d8f4c24 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 16 Feb 2022 13:13:40 +0000 Subject: [PATCH 3/3] Fixing #4522 - frontend-core refactor changed how some of these endpoints were used. --- .../src/pages/builder/portal/manage/users/index.svelte | 4 ++-- packages/builder/src/stores/portal/users.js | 4 ++-- packages/frontend-core/src/api/user.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/manage/users/index.svelte b/packages/builder/src/pages/builder/portal/manage/users/index.svelte index 61192063cc..1160cc109b 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/index.svelte @@ -43,7 +43,7 @@ let createUserModal let basicOnboardingModal - function openBasicOnoboardingModal() { + function openBasicOnboardingModal() { createUserModal.hide() basicOnboardingModal.show() } @@ -91,7 +91,7 @@ - + diff --git a/packages/builder/src/stores/portal/users.js b/packages/builder/src/stores/portal/users.js index cebf03d4c0..0b6b8f563a 100644 --- a/packages/builder/src/stores/portal/users.js +++ b/packages/builder/src/stores/portal/users.js @@ -11,7 +11,7 @@ export function createUsersStore() { } async function invite({ email, builder, admin }) { - await API.inviteUser({ + return API.inviteUser({ email, builder, admin, @@ -19,7 +19,7 @@ export function createUsersStore() { } async function acceptInvite(inviteCode, password) { - await API.acceptInvite({ + return API.acceptInvite({ inviteCode, password, }) diff --git a/packages/frontend-core/src/api/user.js b/packages/frontend-core/src/api/user.js index d1fe7f7251..cfe66873f4 100644 --- a/packages/frontend-core/src/api/user.js +++ b/packages/frontend-core/src/api/user.js @@ -113,11 +113,11 @@ export const buildUserEndpoints = API => ({ }, /** - * Accepts an invitation to join the platform and creates a user. + * Accepts an invite to join the platform and creates a user. * @param inviteCode the invite code sent in the email * @param password the password for the newly created user */ - acceptInvitation: async ({ inviteCode, password }) => { + acceptInvite: async ({ inviteCode, password }) => { return await API.post({ url: "/api/global/users/invite/accept", body: {