Do not cache the archive find toggle; keep only the event-id cache.
The enabled flag must take effect immediately when an admin turns it off.
This commit is contained in:
1 parent
602c64ca0d
commit
7edac9dae1
2 files changed
+6
-18
No files matched your search
@@ -31,7 +31,6 @@ interface Deps {
|
||||
|
||||
const SourceParams = z.object({ sourceId: z.uuid() });
|
||||
const EVENTS_TTL_MS = 5 * 60_000;
|
||||
const SOURCE_TTL_MS = 60_000;
|
||||
const NEAREST = 400;
|
||||
const MAX_PHOTOS = 500;
|
||||
|
||||
@@ -42,8 +41,6 @@ const levelOf = (score: number, match: number): CardLevel => (score >= match ? "
|
||||
export async function registerArchiveFindRoutes(app: FastifyInstance, deps: Deps) {
|
||||
const { db, signer, lookup, viewerOf, visibleFolders, editableFolders } = deps;
|
||||
|
||||
/** Source settings: biometrics / option, shared across requests for a minute. */
|
||||
const sourceCache = new Map<string, { at: number; value: { id: string; organizationId: string; photoFindEnabled: boolean; biometrics: boolean } | null }>();
|
||||
/** Event ids of a viewer's archive scope: the heavy DISTINCT over cloud_files, reused while they search. */
|
||||
const eventsCache = new Map<string, { at: number; ids: string[] }>();
|
||||
|
||||
@@ -61,23 +58,14 @@ export async function registerArchiveFindRoutes(app: FastifyInstance, deps: Deps
|
||||
const requireFind = async (v: Viewer) => {
|
||||
const editable = await editableFolders(v);
|
||||
if (editable !== "all" && !editable.length) throw forbidden("archive_edit_required");
|
||||
const hit = sourceCache.get(v.s);
|
||||
if (hit && Date.now() - hit.at < SOURCE_TTL_MS) {
|
||||
if (!hit.value) throw notFound("source_not_found");
|
||||
if (!hit.value.photoFindEnabled || !hit.value.biometrics) throw conflict("find_unavailable");
|
||||
return hit.value;
|
||||
}
|
||||
// Always read the option from the DB so turning it off takes effect at once (not cached).
|
||||
const source = await db.cloudSource.findUnique({
|
||||
where: { id: v.s },
|
||||
select: { id: true, organizationId: true, photoFindEnabled: true, organization: { select: { biometricsEnabled: true } } },
|
||||
});
|
||||
const value = source
|
||||
? { id: source.id, organizationId: source.organizationId, photoFindEnabled: source.photoFindEnabled, biometrics: source.organization.biometricsEnabled }
|
||||
: null;
|
||||
sourceCache.set(v.s, { at: Date.now(), value });
|
||||
if (!value) throw notFound("source_not_found");
|
||||
if (!value.photoFindEnabled || !value.biometrics) throw conflict("find_unavailable");
|
||||
return value;
|
||||
if (!source) throw notFound("source_not_found");
|
||||
if (!source.photoFindEnabled || !source.organization.biometricsEnabled) throw conflict("find_unavailable");
|
||||
return source;
|
||||
};
|
||||
|
||||
const eventsInScope = async (sourceId: string, scope: Prisma.Sql, cacheKey: string): Promise<string[]> => {
|
||||
|
||||
+2
-2
@@ -238,8 +238,8 @@ When `cloud_sources.photo_find_enabled` is on (default off; on for FPA) and the
|
||||
viewers with edit rights on at least one folder see "Procurar por foto": they upload a portrait (read in memory,
|
||||
never kept) and the archive returns matching photos in the folders they may see (`POST /v1/archive/:source/find`).
|
||||
Same gate as face review — Federação, Ana Teixeira, etc., not read-only viewers and not the public "Encontra-te".
|
||||
Groups are ranked with pgvector HNSW (`centroid_vec`); event ids of the viewer's scope and the source's find
|
||||
settings are cached a few minutes. `GET …/find/ready` starts the face engine before the first upload.
|
||||
Groups are ranked with pgvector HNSW (`centroid_vec`); event ids of the viewer's scope are cached a few minutes.
|
||||
`GET …/find/ready` starts the face engine before the first upload.
|
||||
|
||||
### Face review (viewers who edit on the cloud)
|
||||
|
||||
|
||||
Reference in new issue
Block a user