CRITICAL CHECKPOINT - DO NOT PUSH TO GITHUB Recovery Status: - Successfully recovered brainy.ts from compiled JavaScript - All core v3.0 API methods functional (add, get, update, delete, relate, find, etc.) - Neural subsystem intact (562KB embedded patterns, NLP working) - Augmentation pipeline operational (20+ augmentations) - HNSW clustering system complete - Triple Intelligence compiled (needs constructor fix) - Test suite validates functionality Changes preserved: - 898 files with changes from last 3 days - 144,475 insertions - All augmentation improvements - All test coverage enhancements - Complete v3.0 feature set This is a LOCAL checkpoint only - contains recovered work after corruption incident. Created backup in .backups/brainy-full-20250910-151314.tar.gz Branch: recovery-checkpoint-20250910-151433 Date: Wed Sep 10 03:18:04 PM PDT 2025
91 lines
2.2 KiB
TypeScript
91 lines
2.2 KiB
TypeScript
/**
|
|
* Request Coalescer
|
|
* Batches and deduplicates operations to reduce S3 API calls
|
|
* Automatically flushes based on size, time, or pressure
|
|
*/
|
|
interface CoalescedOperation {
|
|
type: 'write' | 'read' | 'delete';
|
|
key: string;
|
|
data?: any;
|
|
resolve: (value: any) => void;
|
|
reject: (error: any) => void;
|
|
timestamp: number;
|
|
}
|
|
interface BatchStats {
|
|
totalOperations: number;
|
|
coalescedOperations: number;
|
|
deduplicated: number;
|
|
batchesProcessed: number;
|
|
averageBatchSize: number;
|
|
}
|
|
/**
|
|
* Coalesces multiple operations into efficient batches
|
|
*/
|
|
export declare class RequestCoalescer {
|
|
private logger;
|
|
private writeQueue;
|
|
private readQueue;
|
|
private deleteQueue;
|
|
private maxBatchSize;
|
|
private maxBatchAge;
|
|
private minBatchSize;
|
|
private flushTimer;
|
|
private lastFlush;
|
|
private stats;
|
|
private processor;
|
|
constructor(processor: (batch: CoalescedOperation[]) => Promise<void>, options?: {
|
|
maxBatchSize?: number;
|
|
maxBatchAge?: number;
|
|
minBatchSize?: number;
|
|
});
|
|
/**
|
|
* Add a write operation to be coalesced
|
|
*/
|
|
write(key: string, data: any): Promise<void>;
|
|
/**
|
|
* Add a read operation to be coalesced
|
|
*/
|
|
read(key: string): Promise<any>;
|
|
/**
|
|
* Add a delete operation to be coalesced
|
|
*/
|
|
delete(key: string): Promise<void>;
|
|
/**
|
|
* Check if we should flush the queues
|
|
*/
|
|
private checkFlush;
|
|
/**
|
|
* Flush all queued operations
|
|
*/
|
|
flush(reason?: string): Promise<void>;
|
|
/**
|
|
* Get current statistics
|
|
*/
|
|
getStats(): BatchStats;
|
|
/**
|
|
* Get current queue sizes
|
|
*/
|
|
getQueueSizes(): {
|
|
writes: number;
|
|
reads: number;
|
|
deletes: number;
|
|
total: number;
|
|
};
|
|
/**
|
|
* Adjust batch parameters based on load
|
|
*/
|
|
adjustParameters(pending: number): void;
|
|
/**
|
|
* Force immediate flush of all operations
|
|
*/
|
|
forceFlush(): Promise<void>;
|
|
}
|
|
/**
|
|
* Get or create a coalescer for a storage instance
|
|
*/
|
|
export declare function getCoalescer(storageId: string, processor: (batch: any[]) => Promise<void>): RequestCoalescer;
|
|
/**
|
|
* Clear all coalescers
|
|
*/
|
|
export declare function clearCoalescers(): void;
|
|
export {};
|