Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/tools/advanced-caching/cache-benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

Expand Down
4 changes: 2 additions & 2 deletions src/tools/advanced-caching/cache-compression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand All @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions src/tools/api-database/smart-api-fetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* Smart API Fetch Tool - 83% Token Reduction
*
* HTTP client with intelligent features:
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 19 additions & 1 deletion src/tools/api-database/smart-database.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/tools/api-database/smart-graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
4 changes: 2 additions & 2 deletions src/tools/api-database/smart-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
Expand Down