Skip to content

Commit ebdf77e

Browse files
author
n3kosempai
committed
[release] optimization of times using db
1 parent 9eae689 commit ebdf77e

9 files changed

Lines changed: 58 additions & 31 deletions

File tree

src/i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
"kernel": "Kernel",
205205
"diskUsage": "Disk Usage",
206206
"loading": "Loading installed apps...",
207+
"loadingCacheNote": "Caching data for faster future access",
207208
"noApps": "No apps installed",
208209
"permissions": "Permissions",
209210
"storage": "Storage",

src/i18n/locales/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206
"kernel": "Kernel",
207207
"diskUsage": "Uso del Disco",
208208
"loading": "Cargando apps instaladas...",
209+
"loadingCacheNote": "Almacenando datos en caché para acceso más rápido",
209210
"noApps": "No hay apps instaladas",
210211
"permissions": "Permisos",
211212
"storage": "Almacenamiento",

src/i18n/locales/hi.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
"kernel": "कर्नेल",
206206
"diskUsage": "डिस्क उपयोग",
207207
"loading": "इंस्टॉल किए गए ऐप्स लोड हो रहे हैं...",
208+
"loadingCacheNote": "तेज़ एक्सेस के लिए डेटा कैश किया जा रहा है",
208209
"noApps": "कोई ऐप इंस्टॉल नहीं है",
209210
"permissions": "अनुमतियां",
210211
"storage": "स्टोरेज",

src/i18n/locales/ja.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
"kernel": "カーネル",
205205
"diskUsage": "ディスク使用量",
206206
"loading": "インストール済みアプリを読み込み中...",
207+
"loadingCacheNote": "高速アクセスのためにデータをキャッシュしています",
207208
"noApps": "インストールされたアプリはありません",
208209
"permissions": "権限",
209210
"storage": "ストレージ",

src/i18n/locales/pt.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
"kernel": "Kernel",
206206
"diskUsage": "Uso do Disco",
207207
"loading": "Carregando apps instalados...",
208+
"loadingCacheNote": "Armazenando dados em cache para acesso mais rápido",
208209
"noApps": "Nenhum app instalado",
209210
"permissions": "Permissões",
210211
"storage": "Armazenamento",

src/i18n/locales/ru.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
"kernel": "Ядро",
206206
"diskUsage": "Использование диска",
207207
"loading": "Загрузка установленных приложений...",
208+
"loadingCacheNote": "Кэширование данных для ускорения доступа",
208209
"noApps": "Приложения не установлены",
209210
"permissions": "Разрешения",
210211
"storage": "Хранилище",

src/i18n/locales/zh.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
"kernel": "内核",
206206
"diskUsage": "磁盘使用情况",
207207
"loading": "正在加载已安装的应用...",
208+
"loadingCacheNote": "缓存数据以实现更快的访问",
208209
"noApps": "未安装应用",
209210
"permissions": "权限",
210211
"storage": "存储",

src/pages/analytics/components/DataCube.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,23 @@ export const DataCube = ({
441441
}}
442442
>
443443
<CircularProgress sx={{ color: "#58a6ff" }} />
444-
<Typography sx={{ color: "#8b949e", fontFamily: "monospace" }}>
445-
{loading ? t("analytics.loading") : t("analytics.noApps")}
446-
</Typography>
444+
<Box sx={{ textAlign: "center" }}>
445+
<Typography sx={{ color: "#8b949e", fontFamily: "monospace" }}>
446+
{loading ? t("analytics.loading") : t("analytics.noApps")}
447+
</Typography>
448+
{loading && (
449+
<Typography
450+
sx={{
451+
color: "#6e7681",
452+
fontFamily: "monospace",
453+
fontSize: "0.75rem",
454+
mt: 0.5,
455+
}}
456+
>
457+
{t("analytics.loadingCacheNote")}
458+
</Typography>
459+
)}
460+
</Box>
447461
</Box>
448462
);
449463
}

src/utils/dbCache.ts

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -415,14 +415,29 @@ export class DBCacheManager {
415415
const result: Record<string, string[]> = {};
416416

417417
try {
418-
for (const app of apps) {
419-
const permissions = await this.getCachedPermissions(
420-
app.appId,
421-
app.version,
422-
);
423-
if (permissions) {
424-
result[app.appId] = permissions;
425-
}
418+
if (apps.length === 0) return result;
419+
420+
// Build a single query with placeholders for all (app_id, version) pairs
421+
const placeholders = apps
422+
.map(() => "(?, ?)")
423+
.join(", ");
424+
425+
const values = apps.flatMap((app) => [app.appId, app.version]);
426+
427+
const rows = await this.db.select<
428+
Array<{
429+
app_id: string;
430+
permissions: string;
431+
outdated: number;
432+
}>
433+
>(
434+
`SELECT app_id, permissions, outdated FROM app_permissions
435+
WHERE (app_id, version) IN (VALUES ${placeholders}) AND outdated = 0`,
436+
values,
437+
);
438+
439+
for (const row of rows) {
440+
result[row.app_id] = JSON.parse(row.permissions);
426441
}
427442
} catch (error) {
428443
console.error("Error reading cached permissions batch:", error);
@@ -437,27 +452,18 @@ export class DBCacheManager {
437452
await this.initialize();
438453
if (!this.db) throw new Error("Database not initialized");
439454

440-
try {
441-
const entries = Object.entries(permissionsMap);
442-
if (entries.length === 0) return;
443-
444-
// Use explicit transaction for batch inserts (10-100x faster)
445-
await this.db.execute("BEGIN TRANSACTION");
455+
const entries = Object.entries(permissionsMap);
456+
if (entries.length === 0) return;
446457

447-
try {
448-
for (const [appId, data] of entries) {
449-
const permissionsStr = JSON.stringify(data.permissions);
450-
await this.db.execute(
451-
`INSERT OR REPLACE INTO app_permissions (app_id, version, permissions, outdated, cached_at)
452-
VALUES (?, ?, ?, 0, CURRENT_TIMESTAMP)`,
453-
[appId, data.version, permissionsStr],
454-
);
455-
}
456-
457-
await this.db.execute("COMMIT");
458-
} catch (error) {
459-
await this.db.execute("ROLLBACK");
460-
throw error;
458+
try {
459+
// Insert each permission sequentially (no transaction to avoid locks)
460+
for (const [appId, data] of entries) {
461+
const permissionsStr = JSON.stringify(data.permissions);
462+
await this.db.execute(
463+
`INSERT OR REPLACE INTO app_permissions (app_id, version, permissions, outdated, cached_at)
464+
VALUES (?, ?, ?, 0, CURRENT_TIMESTAMP)`,
465+
[appId, data.version, permissionsStr],
466+
);
461467
}
462468
} catch (error) {
463469
console.error("Error caching permissions batch:", error);

0 commit comments

Comments
 (0)