feat: add knowledge module caching layer (closes #79)

This commit is contained in:
Jason Woltje
2026-01-30 00:05:52 -06:00
parent 806a518467
commit 90abe2a9b2
10 changed files with 1009 additions and 9 deletions

View File

@@ -5,6 +5,7 @@ import type {
KnowledgeEntryWithTags,
PaginatedEntries,
} from "../entities/knowledge-entry.entity";
import { KnowledgeCacheService } from "./cache.service";
/**
* Search options for full-text search
@@ -63,7 +64,10 @@ interface RawSearchResult {
*/
@Injectable()
export class SearchService {
constructor(private readonly prisma: PrismaService) {}
constructor(
private readonly prisma: PrismaService,
private readonly cache: KnowledgeCacheService
) {}
/**
* Full-text search on title and content using PostgreSQL ts_vector
@@ -98,6 +102,13 @@ export class SearchService {
};
}
// Check cache first
const filters = { status: options.status, page, limit };
const cached = await this.cache.getSearch(workspaceId, sanitizedQuery, filters);
if (cached) {
return cached;
}
// Build status filter
const statusFilter = options.status
? Prisma.sql`AND e.status = ${options.status}::text::"EntryStatus"`
@@ -184,7 +195,7 @@ export class SearchService {
tags: tagsMap.get(row.id) || [],
}));
return {
const result = {
data,
pagination: {
page,
@@ -194,6 +205,11 @@ export class SearchService {
},
query,
};
// Cache the result
await this.cache.setSearch(workspaceId, sanitizedQuery, filters, result);
return result;
}
/**