diff --git a/src/tools/advanced-caching/cache-benchmark.ts b/src/tools/advanced-caching/cache-benchmark.ts index d28bd1c..71d576c 100644 --- a/src/tools/advanced-caching/cache-benchmark.ts +++ b/src/tools/advanced-caching/cache-benchmark.ts @@ -411,10 +411,7 @@ class BenchmarkExecutor { const latency = Number(endTime - startTime) / 1_000_000; // Convert to ms - this.latencies.push( - latency /* originalSize */, - config.ttl || 3600 /* compressedSize */, - ); + this.latencies.push(latency); this.operations.push({ type: "write", timestamp: Date.now(), latency }); } diff --git a/src/tools/advanced-caching/cache-compression.ts b/src/tools/advanced-caching/cache-compression.ts index 7190eec..882b059 100644 --- a/src/tools/advanced-caching/cache-compression.ts +++ b/src/tools/advanced-caching/cache-compression.ts @@ -1272,7 +1272,7 @@ export class CacheCompressionTool { } else if (typeof data === "string") { return Buffer.from(data, "utf-8"); } else { - return Buffer.from(JSON.stringify(data), 'utf-8'); + return Buffer.from(JSON.stringify(data), "utf-8"); } } @@ -1292,7 +1292,7 @@ export class CacheCompressionTool { active: i % 2 === 0, })), }; - return Buffer.from(JSON.stringify(obj), 'utf-8'); + return Buffer.from(JSON.stringify(obj), "utf-8"); } case "text": { diff --git a/src/tools/api-database/smart-api-fetch.ts b/src/tools/api-database/smart-api-fetch.ts index 1630a55..8b54f70 100644 --- a/src/tools/api-database/smart-api-fetch.ts +++ b/src/tools/api-database/smart-api-fetch.ts @@ -1,4 +1,4 @@ -/** +/** * Smart API Fetch Tool - 83% Token Reduction * * HTTP client with intelligent features: @@ -427,7 +427,7 @@ export class SmartApiFetch { } try { - const result = JSON.parse(cached) as SmartApiFetchResult; + const result = JSON.parse(cached.toString('utf-8')) as SmartApiFetchResult; // Check if cache is still valid const age = (Date.now() - result.timestamp) / 1000; diff --git a/src/tools/api-database/smart-database.ts b/src/tools/api-database/smart-database.ts index b279870..d8a1764 100644 --- a/src/tools/api-database/smart-database.ts +++ b/src/tools/api-database/smart-database.ts @@ -1,4 +1,22 @@ -/** * Smart Database - Database Query Optimizer with 83% Token Reduction * * Features: * - Query execution with intelligent result caching * - Query plan analysis (EXPLAIN) * - Index usage detection and recommendations * - Query optimization suggestions * - Slow query detection and bottleneck analysis * - Connection pooling information * - Query performance tracking * * Token Reduction Strategy: * - Cached queries: Row count only (95% reduction) * - EXPLAIN analysis: Plan summary (85% reduction) * - Query execution: Top 10 rows (80% reduction) * - Analysis only: Query info + suggestions (90% reduction) * - Average: 83% reduction */ import { createHash } from "crypto"; +/** + * Smart Database - Database Query Optimizer with 83% Token Reduction + * + * Features: + * - Query execution with intelligent result caching + * - Query plan analysis (EXPLAIN) + * - Index usage detection and recommendations + * - Query optimization suggestions + * - Slow query detection and bottleneck analysis + * - Connection pooling information + * - Query performance tracking + * + * Token Reduction Strategy: + * - Cached queries: Row count only (95% reduction) + * - EXPLAIN analysis: Plan summary (85% reduction) + * - Query execution: Top 10 rows (80% reduction) + * - Analysis only: Query info + suggestions (90% reduction) + * - Average: 83% reduction + */ import { createHash } from "crypto"; import type { CacheEngine } from "../../core/cache-engine"; import type { TokenCounter } from "../../core/token-counter"; import type { MetricsCollector } from "../../core/metrics"; diff --git a/src/tools/api-database/smart-graphql.ts b/src/tools/api-database/smart-graphql.ts index 71160fb..9976714 100644 --- a/src/tools/api-database/smart-graphql.ts +++ b/src/tools/api-database/smart-graphql.ts @@ -587,7 +587,7 @@ export class SmartGraphQL { // Cache for 1 hour await this.cache.set( cacheKey, - Buffer.from(JSON.stringify(schemaInfo)).toString("utf-8"), + JSON.stringify(schemaInfo), 0, 3600, ); diff --git a/src/tools/api-database/smart-migration.ts b/src/tools/api-database/smart-migration.ts index da880a2..884767d 100644 --- a/src/tools/api-database/smart-migration.ts +++ b/src/tools/api-database/smart-migration.ts @@ -524,8 +524,8 @@ CREATE TABLE IF NOT EXISTS example ( } catch (error) { // Caching failure should not break the operation console.error( - "Failed to cache migration result:" /* originalSize */, - (ttl || 3600) * 1000 /* compressedSize */, + "Failed to cache migration result:", + error ); } }