import { existsSync, statSync } from "node:fs";
import { join } from "node:path";
import Database from "better-sqlite3";
function readCacheStats(dataDir) {
  const dbPath = join(dataDir, "cache.db");
  if (!existsSync(dbPath)) return { pages: 0, bytes: 0 };
  let bytes = 0;
  try {
    const stat = statSync(dbPath);
    if (!stat.isFile()) return { pages: 0, bytes: 0 };
    bytes = stat.size;
  } catch {
    return { pages: 0, bytes: 0 };
  }
  let pages = 0;
  let db = null;
  try {
    db = new Database(dbPath, { readonly: true, fileMustExist: true });
    const row = db.prepare(
      "SELECT count(*) AS c FROM sqlite_master WHERE type='table' AND name='url_cache'"
    ).get();
    if (row.c > 0) {
      const count = db.prepare("SELECT count(*) AS c FROM url_cache").get();
      pages = count.c;
    }
  } catch {
    pages = 0;
  } finally {
    try {
      db?.close();
    } catch {
    }
  }
  return { pages, bytes };
}
export {
  readCacheStats
};
//# sourceMappingURL=status-cache.js.map