perf: implement Phase 1 homepage diet via Next.js Cache Components
P1-0: V8 heap cap (HOMARR_MAX_OLD_SPACE_SIZE, default 512MB)
P1-1: Module graph cuts
- Dynamic integration imports (55 static → lazy loaders)
- Conditional DB driver loading (only configured driver loaded)
- Replace jsdom with linkedom for SVG sanitization
- Delete eager widget barrel (55 import * as → 0)
- Extract createRetryableLoader to @homarr/common
P1-2: Enable cacheComponents + restructure root layout
- Suspense boundaries around session-dependent providers
- ColorSchemeScript replaces server-side cookie reads
- Board/manage/auth layouts wrapped in Suspense
P1-3: Cache read paths
- Cache tag registry + invalidation helpers
- Cache invalidation wired into all mutation routers
- Translation deep-merge memoized per locale
P1-4: Prerendered shells + loading.tsx files
P1-5: Shared integration data cache (60s TTL, stale-while-revalidate)
P1-6: Redis-backed Next.js cache handler (@homarr/next-cache-handler)
P1-7: Redis optional (memory channel fallback), TTL on pubSub:last:*,
Redis clients consolidated from 6 to 2
This commit is contained in:
86 files changed
+2219
-1232
No files matched your search
@@ -1,12 +1,15 @@
|
||||
import { createRequire } from "node:module";
|
||||
|
||||
import { DB_CASING } from "../constants";
|
||||
import { createDbMapping } from "../mapping";
|
||||
import { createMysqlDb } from "./mysql";
|
||||
import { createPostgresDb } from "./postgresql";
|
||||
import { dbEnv } from "../env";
|
||||
import type { SharedDrizzleConfig } from "./shared";
|
||||
import { WinstonDrizzleLogger } from "./shared";
|
||||
import { createSqliteDb } from "./sqlite";
|
||||
|
||||
export type Database<TSchema extends Record<string, unknown>> = ReturnType<typeof createSqliteDb<TSchema>>;
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
export type Database<TSchema extends Record<string, unknown>> = ReturnType<
|
||||
typeof import("./sqlite").createSqliteDb<TSchema>
|
||||
>;
|
||||
|
||||
export const createSharedConfig = <TSchema extends Record<string, unknown>>(
|
||||
schema: TSchema,
|
||||
@@ -18,10 +21,15 @@ export const createSharedConfig = <TSchema extends Record<string, unknown>>(
|
||||
|
||||
export const createDb = <TSchema extends Record<string, unknown>>(schema: TSchema) => {
|
||||
const config = createSharedConfig(schema);
|
||||
|
||||
return createDbMapping({
|
||||
mysql2: () => createMysqlDb(config),
|
||||
"node-postgres": () => createPostgresDb(config),
|
||||
"better-sqlite3": () => createSqliteDb(config),
|
||||
});
|
||||
// ponytail: conditional require — only the configured driver is loaded.
|
||||
// Ceiling: all 3 stay on disk for runtime driver switching; only loaded graph shrinks.
|
||||
const driver = dbEnv.DRIVER ?? "better-sqlite3";
|
||||
switch (driver) {
|
||||
case "mysql2":
|
||||
return (require("./mysql") as typeof import("./mysql")).createMysqlDb(config);
|
||||
case "node-postgres":
|
||||
return (require("./postgresql") as typeof import("./postgresql")).createPostgresDb(config);
|
||||
default:
|
||||
return (require("./sqlite") as typeof import("./sqlite")).createSqliteDb(config);
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user