From a81c01e38a46368122eaecba7d05e5d3cbbd7dfd Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 5 May 2026 23:57:08 +0530 Subject: [PATCH 1/2] perf: eliminate wasted API call, afterUpdate overhead, and sequential billing checks - Remove unused projects.list() call fired on every console load (result was never consumed) - Replace afterUpdate with reactive headerAlert subscription to avoid per-render overhead - Parallelize billing checks with Promise.all instead of sequential awaits - Fix database.subscribe() memory leak by wrapping in onMount for proper cleanup --- src/routes/(console)/+layout.svelte | 29 ++++++++++++++++------------- src/routes/(console)/+layout.ts | 26 +------------------------- 2 files changed, 17 insertions(+), 38 deletions(-) diff --git a/src/routes/(console)/+layout.svelte b/src/routes/(console)/+layout.svelte index ea0830ac0c..56a14d6262 100644 --- a/src/routes/(console)/+layout.svelte +++ b/src/routes/(console)/+layout.svelte @@ -8,7 +8,7 @@ import { database, checkForDatabaseBackupPolicies } from '$lib/stores/database'; import { newOrgModal, organization } from '$lib/stores/organization'; import { wizard } from '$lib/stores/wizard'; - import { afterUpdate, onMount } from 'svelte'; + import { onMount } from 'svelte'; import { loading } from '$routes/store'; import { requestedMigration } from '../store'; import Create from './createOrganization.svelte'; @@ -280,10 +280,12 @@ } } - database.subscribe(async (database) => { - if (!database || !page.params.region || !page.params.project) return; - // the component checks `isCloud` internally. - await checkForDatabaseBackupPolicies(page.params.region, page.params.project, database); + onMount(() => { + return database.subscribe(async (database) => { + if (!database || !page.params.region || !page.params.project) return; + // the component checks `isCloud` internally. + await checkForDatabaseBackupPolicies(page.params.region, page.params.project, database); + }); }); let currentOrganizationId = null; @@ -293,18 +295,21 @@ if (isCloud) { currentOrganizationId = org.$id; checkForEnterpriseTrial(org); - await checkForUsageLimit(org); checkForMarkedForDeletion(org); - await checkForNewDevUpgradePro(org); - if (org?.billingPlanDetails.requiresPaymentMethod) { - await paymentExpired(org); - await checkPaymentAuthorizationRequired(org); + const billingChecks: Promise[] = [ + checkForUsageLimit(org), + checkForNewDevUpgradePro(org) + ]; + if (org?.billingPlanDetails.requiresPaymentMethod) { + billingChecks.push(paymentExpired(org), checkPaymentAuthorizationRequired(org)); if (org?.billingTrialDays) { calculateTrialDay(org); } } + + await Promise.all(billingChecks); $activeHeaderAlert = headerAlert.getExcluding('impersonation'); } } @@ -317,9 +322,7 @@ $registerSearchers(orgSearcher, projectsSearcher); - afterUpdate(() => { - $activeHeaderAlert = headerAlert.getExcluding('impersonation'); - }); + $: void $headerAlert, ($activeHeaderAlert = headerAlert.getExcluding('impersonation')); diff --git a/src/routes/(console)/+layout.ts b/src/routes/(console)/+layout.ts index f40123b438..b191a64364 100644 --- a/src/routes/(console)/+layout.ts +++ b/src/routes/(console)/+layout.ts @@ -3,7 +3,7 @@ import { isCloud } from '$lib/system'; import type { LayoutLoad } from './$types'; import type { Account } from '$lib/stores/user'; import { Dependencies } from '$lib/constants'; -import { Platform, Query, type Models } from '@appwrite.io/console'; +import { Platform, type Models } from '@appwrite.io/console'; import { makePlansMap } from '$lib/helpers/billing'; import { plansInfo as plansInfoStore } from '$lib/stores/billing'; import { normalizeConsoleVariables } from '$lib/helpers/domains'; @@ -54,7 +54,6 @@ export const load: LayoutLoad = async ({ depends, parent, url }) => { currentOrgId: undefined, organizations, consoleVariables, - allProjectsCount: 0, plansInfo: plansInfo ?? null, version: versionData?.version ?? null }; @@ -107,28 +106,6 @@ export const load: LayoutLoad = async ({ depends, parent, url }) => { preferences.organization ?? (organizations.teams.length > 0 ? organizations.teams[0].$id : undefined); - // Load projects for the current organization if one is selected - let projectsCount = 0; - if (currentOrgId) { - try { - projectsCount = ( - await sdk.forConsole.projects.list({ - queries: [ - Query.equal('teamId', currentOrgId), - Query.limit(1), - Query.select(['$id']) - ] - }) - ).total; - } catch (e) { - if (shouldRedirectToVerifyEmail(e)) { - redirect(303, verifyEmailUrl); - } - - projectsCount = 0; - } - } - // just in case! plansInfoStore.set(fallbackPlansInfoArray); @@ -139,7 +116,6 @@ export const load: LayoutLoad = async ({ depends, parent, url }) => { currentOrgId, organizations, consoleVariables, - allProjectsCount: projectsCount, plansInfo: fallbackPlansInfoArray, version: versionData?.version ?? null }; From aad9c7fe2f3d82069e624c3e4bbc9216aacbd5d0 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Wed, 6 May 2026 00:00:47 +0530 Subject: [PATCH 2/2] lint --- src/routes/(console)/+layout.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/(console)/+layout.svelte b/src/routes/(console)/+layout.svelte index 56a14d6262..5b3072210c 100644 --- a/src/routes/(console)/+layout.svelte +++ b/src/routes/(console)/+layout.svelte @@ -322,7 +322,7 @@ $registerSearchers(orgSearcher, projectsSearcher); - $: void $headerAlert, ($activeHeaderAlert = headerAlert.getExcluding('impersonation')); + $: (void $headerAlert, ($activeHeaderAlert = headerAlert.getExcluding('impersonation')));