From 603b7da9e60387dc3efa70cb26c3dd8ba9dff946 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Sat, 3 Jan 2026 14:38:00 +0500 Subject: [PATCH] server(theme): update theme's install count immediately on install --- servers/themes/src/api.ts | 9 +++++++-- servers/themes/src/orama.ts | 10 +++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/servers/themes/src/api.ts b/servers/themes/src/api.ts index bd64fcc5b..3fb03f8ea 100644 --- a/servers/themes/src/api.ts +++ b/servers/themes/src/api.ts @@ -19,7 +19,7 @@ along with this program. If not, see . import { z } from "zod"; import { InstallsCounter } from "./constants"; -import { findTheme, getThemes } from "./orama"; +import { findTheme, getThemes, updateTotalInstalls } from "./orama"; import { syncThemes } from "./sync"; import { publicProcedure, router } from "./trpc"; import { THEME_COMPATIBILITY_VERSION } from "@notesnook/theme"; @@ -41,7 +41,12 @@ export const ThemesAPI = router({ const theme = await findTheme(id, compatibilityVersion); if (!theme) return; - if (userId) await InstallsCounter.increment(theme.id, userId); + if (userId) { + updateTotalInstalls( + theme, + await InstallsCounter.increment(theme.id, userId) + ); + } return theme; }), updateTheme: publicProcedure diff --git a/servers/themes/src/orama.ts b/servers/themes/src/orama.ts index d07b35da3..8f970c97f 100644 --- a/servers/themes/src/orama.ts +++ b/servers/themes/src/orama.ts @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ -import { Orama, SearchParams, create, search } from "@orama/orama"; +import { Orama, SearchParams, create, search, update } from "@orama/orama"; import { CompiledThemeDefinition, ThemeMetadata } from "./sync"; import { ThemeQuerySchema } from "./schemas"; @@ -54,6 +54,14 @@ export async function findTheme( return results.hits[0].document as CompiledThemeDefinition; } +export async function updateTotalInstalls( + theme: CompiledThemeDefinition, + totalInstalls: number +) { + if (!ThemesDatabase) await initializeDatabase(); + await update(ThemesDatabase!, theme.id, { ...theme, totalInstalls }); +} + export async function getThemes(query: (typeof ThemeQuerySchema)["_type"]) { if (!ThemesDatabase) await initializeDatabase();