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();