fix: code review cleanup - remove unused imports, replace any types with generics, fix test imports
This commit is contained in:
@@ -30,8 +30,7 @@ import { KnowledgeCacheService } from "./services/cache.service";
|
|||||||
export class KnowledgeController {
|
export class KnowledgeController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly knowledgeService: KnowledgeService,
|
private readonly knowledgeService: KnowledgeService,
|
||||||
private readonly linkSync: LinkSyncService,
|
private readonly linkSync: LinkSyncService
|
||||||
private readonly cache: KnowledgeCacheService
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { KnowledgeCacheService } from './cache.service';
|
import { KnowledgeCacheService } from './cache.service';
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
|
|||||||
private readonly ENTRY_PREFIX = 'knowledge:entry:';
|
private readonly ENTRY_PREFIX = 'knowledge:entry:';
|
||||||
private readonly SEARCH_PREFIX = 'knowledge:search:';
|
private readonly SEARCH_PREFIX = 'knowledge:search:';
|
||||||
private readonly GRAPH_PREFIX = 'knowledge:graph:';
|
private readonly GRAPH_PREFIX = 'knowledge:graph:';
|
||||||
private readonly STATS_PREFIX = 'knowledge:stats:';
|
|
||||||
|
|
||||||
// Default TTL from environment (default: 5 minutes)
|
// Default TTL from environment (default: 5 minutes)
|
||||||
private readonly DEFAULT_TTL: number;
|
private readonly DEFAULT_TTL: number;
|
||||||
@@ -113,7 +112,7 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
|
|||||||
/**
|
/**
|
||||||
* Get entry from cache by workspace and slug
|
* Get entry from cache by workspace and slug
|
||||||
*/
|
*/
|
||||||
async getEntry(workspaceId: string, slug: string): Promise<any | null> {
|
async getEntry<T = unknown>(workspaceId: string, slug: string): Promise<T | null> {
|
||||||
if (!this.cacheEnabled) return null;
|
if (!this.cacheEnabled) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -124,7 +123,7 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
|
|||||||
this.stats.hits++;
|
this.stats.hits++;
|
||||||
this.updateHitRate();
|
this.updateHitRate();
|
||||||
this.logger.debug(`Cache HIT: ${key}`);
|
this.logger.debug(`Cache HIT: ${key}`);
|
||||||
return JSON.parse(cached);
|
return JSON.parse(cached) as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.stats.misses++;
|
this.stats.misses++;
|
||||||
@@ -140,10 +139,10 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
|
|||||||
/**
|
/**
|
||||||
* Set entry in cache
|
* Set entry in cache
|
||||||
*/
|
*/
|
||||||
async setEntry(
|
async setEntry<T = unknown>(
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
slug: string,
|
slug: string,
|
||||||
data: any,
|
data: T,
|
||||||
options?: CacheOptions
|
options?: CacheOptions
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!this.cacheEnabled) return;
|
if (!this.cacheEnabled) return;
|
||||||
@@ -182,11 +181,11 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
|
|||||||
/**
|
/**
|
||||||
* Get search results from cache
|
* Get search results from cache
|
||||||
*/
|
*/
|
||||||
async getSearch(
|
async getSearch<T = unknown>(
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
query: string,
|
query: string,
|
||||||
filters: Record<string, any>
|
filters: Record<string, unknown>
|
||||||
): Promise<any | null> {
|
): Promise<T | null> {
|
||||||
if (!this.cacheEnabled) return null;
|
if (!this.cacheEnabled) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -197,7 +196,7 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
|
|||||||
this.stats.hits++;
|
this.stats.hits++;
|
||||||
this.updateHitRate();
|
this.updateHitRate();
|
||||||
this.logger.debug(`Cache HIT: ${key}`);
|
this.logger.debug(`Cache HIT: ${key}`);
|
||||||
return JSON.parse(cached);
|
return JSON.parse(cached) as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.stats.misses++;
|
this.stats.misses++;
|
||||||
@@ -213,11 +212,11 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
|
|||||||
/**
|
/**
|
||||||
* Set search results in cache
|
* Set search results in cache
|
||||||
*/
|
*/
|
||||||
async setSearch(
|
async setSearch<T = unknown>(
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
query: string,
|
query: string,
|
||||||
filters: Record<string, any>,
|
filters: Record<string, unknown>,
|
||||||
data: any,
|
data: T,
|
||||||
options?: CacheOptions
|
options?: CacheOptions
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!this.cacheEnabled) return;
|
if (!this.cacheEnabled) return;
|
||||||
@@ -254,11 +253,11 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
|
|||||||
/**
|
/**
|
||||||
* Get graph query results from cache
|
* Get graph query results from cache
|
||||||
*/
|
*/
|
||||||
async getGraph(
|
async getGraph<T = unknown>(
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
entryId: string,
|
entryId: string,
|
||||||
maxDepth: number
|
maxDepth: number
|
||||||
): Promise<any | null> {
|
): Promise<T | null> {
|
||||||
if (!this.cacheEnabled) return null;
|
if (!this.cacheEnabled) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -269,7 +268,7 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
|
|||||||
this.stats.hits++;
|
this.stats.hits++;
|
||||||
this.updateHitRate();
|
this.updateHitRate();
|
||||||
this.logger.debug(`Cache HIT: ${key}`);
|
this.logger.debug(`Cache HIT: ${key}`);
|
||||||
return JSON.parse(cached);
|
return JSON.parse(cached) as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.stats.misses++;
|
this.stats.misses++;
|
||||||
@@ -285,11 +284,11 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
|
|||||||
/**
|
/**
|
||||||
* Set graph query results in cache
|
* Set graph query results in cache
|
||||||
*/
|
*/
|
||||||
async setGraph(
|
async setGraph<T = unknown>(
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
entryId: string,
|
entryId: string,
|
||||||
maxDepth: number,
|
maxDepth: number,
|
||||||
data: any,
|
data: T,
|
||||||
options?: CacheOptions
|
options?: CacheOptions
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!this.cacheEnabled) return;
|
if (!this.cacheEnabled) return;
|
||||||
@@ -399,7 +398,7 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
|
|||||||
private getSearchKey(
|
private getSearchKey(
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
query: string,
|
query: string,
|
||||||
filters: Record<string, any>
|
filters: Record<string, unknown>
|
||||||
): string {
|
): string {
|
||||||
const filterHash = this.hashObject(filters);
|
const filterHash = this.hashObject(filters);
|
||||||
return `${this.SEARCH_PREFIX}${workspaceId}:${query}:${filterHash}`;
|
return `${this.SEARCH_PREFIX}${workspaceId}:${query}:${filterHash}`;
|
||||||
@@ -419,7 +418,7 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
|
|||||||
/**
|
/**
|
||||||
* Hash an object to create a consistent string representation
|
* Hash an object to create a consistent string representation
|
||||||
*/
|
*/
|
||||||
private hashObject(obj: Record<string, any>): string {
|
private hashObject(obj: Record<string, unknown>): string {
|
||||||
return JSON.stringify(obj, Object.keys(obj).sort());
|
return JSON.stringify(obj, Object.keys(obj).sort());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user