Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/server/src/application/services/backup-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getErrorMessage } from "@solid-imager/core/utils/get-error-message";
import type { Table } from "drizzle-orm";
import { and, asc, eq, gt, inArray, lt, or, sql } from "drizzle-orm";
import type { PgColumn } from "drizzle-orm/pg-core";
import { LANCEDB_DUMP_VERSION } from "~/application/services/lancedb-dump-service";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# lancedb-dump-service.ts のトップレベルに重い副作用(LanceDB接続確立など)がないか確認
sed -n '1,20p' packages/application/src/services/lancedb-dump-service.ts
sed -n '1,10p' apps/server/src/application/services/lancedb-dump-service.ts

# backup-service.ts内での同モジュールへのimportパターンを確認
rg -n 'lancedb-dump-service' apps/server/src/application/services/backup-service.ts

Repository: hmjn023/solid-imager

Length of output: 1514


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- backup-service.ts top imports and relevant dynamic imports ---'
sed -n '1,80p' apps/server/src/application/services/backup-service.ts
echo
sed -n '1030,1085p' apps/server/src/application/services/backup-service.ts
echo
sed -n '1260,1295p' apps/server/src/application/services/backup-service.ts
echo
sed -n '1328,1360p' apps/server/src/application/services/backup-service.ts
echo
sed -n '1588,1665p' apps/server/src/application/services/backup-service.ts

echo
echo '--- lancedb-dump-service.ts top of file and all runtime imports ---'
sed -n '1,120p' apps/server/src/application/services/lancedb-dump-service.ts
echo
rg -n 'from "@|from "~/' apps/server/src/application/services/lancedb-dump-service.ts

Repository: hmjn023/solid-imager

Length of output: 8977


静的 import による早期評価を再確認 backup-service.ts で LANCEDB_DUMP_VERSION を静的 import すると、~/application/services/lancedb-dump-service のモジュール初期化自体は走ります。apps/server/src/application/services/lancedb-dump-service.ts では createLanceDbDumpService(...) をトップレベルで呼んでいるため、遅延ロードに寄せたい意図があるならここは動的 import に揃えるべきです。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/server/src/application/services/backup-service.ts` at line 13, The
static import of LANCEDB_DUMP_VERSION in backup-service.ts still eagerly
initializes lancedb-dump-service, which defeats the intended lazy loading.
Update the backup-service code path to load LANCEDB_DUMP_VERSION via a dynamic
import like the existing createLanceDbDumpService flow in lancedb-dump-service,
and keep the import inside the relevant function or runtime branch so module
initialization is deferred. Use the symbols backup-service,
LANCEDB_DUMP_VERSION, and createLanceDbDumpService to locate and align the
change.

import { db } from "~/infrastructure/db";
import {
authorAccounts,
Expand Down Expand Up @@ -1194,7 +1195,7 @@ export const BackupService = {
try {
const content = await fs.readFile(manifestPath, "utf-8");
const manifest = JSON.parse(content) as { version?: unknown };
if (manifest.version !== 3) {
if (manifest.version !== LANCEDB_DUMP_VERSION) {
if (!config.lancedb?.autoFullSync) {
logger.warn(
{ mediaSourceId },
Expand Down
6 changes: 5 additions & 1 deletion apps/server/src/application/services/lancedb-dump-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { createLanceDbDumpService } from "@solid-imager/application/services/lancedb-dump-service";
import {
createLanceDbDumpService,
LANCEDB_DUMP_VERSION,
} from "@solid-imager/application/services/lancedb-dump-service";

export type { MediaDumpItemWithImageData } from "@solid-imager/application/ports/lancedb-dump-service";
export { LANCEDB_DUMP_VERSION };

import { logger } from "~/infrastructure/logger";

Expand Down
5 changes: 4 additions & 1 deletion apps/server/src/application/services/maintenance-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ export class MaintenanceService {
try {
const content = await fs.readFile(manifestPath, "utf-8");
const manifest = JSON.parse(content) as { version?: unknown };
return manifest.version === 3;
const { LANCEDB_DUMP_VERSION } = await import(
"~/application/services/lancedb-dump-service"
);
return manifest.version === LANCEDB_DUMP_VERSION;
} catch {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ vi.mock("~/application/registry", () => ({
// Mock lancedb-dump-service
const mockReadMediaIds = vi.fn();
vi.mock("~/application/services/lancedb-dump-service", () => ({
LANCEDB_DUMP_VERSION: 4,
readMediaIds: mockReadMediaIds,
}));
Comment thread
hmjn023 marked this conversation as resolved.
Resolved

Expand Down Expand Up @@ -387,9 +388,9 @@ describe("MaintenanceService", () => {
]);
mockJobRepo.createIfUnique.mockResolvedValue({ id: "job-new" });

// Simulate manifest.json exists (version: 3)
// Simulate a current manifest.json.
(fs.readFile as unknown as Mock).mockResolvedValue(
JSON.stringify({ version: 3 }),
JSON.stringify({ version: 4 }),
);

// Both LanceDB and Postgres have media-1
Expand Down Expand Up @@ -417,9 +418,9 @@ describe("MaintenanceService", () => {
]);
mockJobRepo.createIfUnique.mockResolvedValue({ id: "job-new" });

// Simulate manifest.json exists (version: 3)
// Simulate a current manifest.json.
(fs.readFile as unknown as Mock).mockResolvedValue(
JSON.stringify({ version: 3 }),
JSON.stringify({ version: 4 }),
);

// Postgres: media-1, media-2
Expand Down Expand Up @@ -465,9 +466,9 @@ describe("MaintenanceService", () => {
]);
mockJobRepo.createIfUnique.mockResolvedValue({ id: "job-new" });

// Simulate manifest.json exists (version: 3)
// Simulate a current manifest.json.
(fs.readFile as unknown as Mock).mockResolvedValue(
JSON.stringify({ version: 3 }),
JSON.stringify({ version: 4 }),
);

// readMediaIds throws error
Expand Down
2 changes: 1 addition & 1 deletion packages/application/src/services/lancedb-dump-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {

const ROW_CHUNK_SIZE = 5000;
const READ_CHUNK_SIZE = 5000;
const LANCEDB_DUMP_VERSION = 4;
export const LANCEDB_DUMP_VERSION = 4;

async function updateLanceDbManifestVersion(lanceDbDir: string): Promise<void> {
const manifestPath = path.join(lanceDbDir, "manifest.json");
Expand Down