Remove unnecessary request queue from proxy.js
Reduced from 298 to 246 lines (52 lines saved, 17% reduction) Rationale: - Proxy.js receives only 1 request at a time per execution context - Each request runs in isolated VM context via server.js - FIFO queue was unnecessary complexity for single-request execution - Node.js HTTP server already handles request queueing at TCP level Changes: - Removed: RequestQueue class (48 lines including getters) - Removed: requestQueue singleton instance - Removed: Queue wrapping in main handler - Updated: Direct call to handleSitemapRequest() - Updated: Section numbering (2→3, 3→4 removed) - Updated: File header structure documentation Benefits: ✅ Simpler code (17% reduction) ✅ Less cognitive overhead (no queue state to track) ✅ Faster execution (no queue overhead) ✅ Clearer intent (direct async call) ✅ Same functionality (still sequential per VM context) Architecture Note: - server.js creates fresh VM context per request - Each proxy.js execution is inherently isolated - No concurrent access possible within same context - HTTP server manages request ordering at network layer Testing: ✓ Syntax validated ✓ Server starts successfully ✓ Request handling works correctly ✓ No queue-related functionality needed Progressive Simplification: - Start: 752 lines (monolithic with utilities) - After helper extraction: 493 lines (-35%) - After moderate cleanup: 298 lines (-60%) - After queue removal: 246 lines (-67% total) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -25,9 +25,8 @@
|
|||||||
*
|
*
|
||||||
* Structure:
|
* Structure:
|
||||||
* Section 1: Authentication (Service Account JWT)
|
* Section 1: Authentication (Service Account JWT)
|
||||||
* Section 2: Request Queue (FIFO)
|
* Section 2: Drive API Client
|
||||||
* Section 3: Drive API Client
|
* Section 3: Request Handling & Routing
|
||||||
* Section 4: Request Handling & Routing
|
|
||||||
*
|
*
|
||||||
* @module proxy
|
* @module proxy
|
||||||
*/
|
*/
|
||||||
@@ -104,58 +103,7 @@ async function getAccessTokenCached() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// Section 2: Request Queue (FIFO)
|
// Section 2: Drive API Client
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FIFO Queue for sequential request processing
|
|
||||||
* Prevents concurrent Drive API operations per specification
|
|
||||||
*/
|
|
||||||
class RequestQueue {
|
|
||||||
constructor() {
|
|
||||||
this.queue = [];
|
|
||||||
this.processing = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
async enqueue(handler) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this.queue.push({ handler, resolve, reject });
|
|
||||||
if (!this.processing) this._processNext();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async _processNext() {
|
|
||||||
if (this.queue.length === 0) {
|
|
||||||
this.processing = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.processing = true;
|
|
||||||
const { handler, resolve, reject } = this.queue.shift();
|
|
||||||
|
|
||||||
try {
|
|
||||||
resolve(await handler());
|
|
||||||
} catch (error) {
|
|
||||||
reject(error);
|
|
||||||
} finally {
|
|
||||||
this._processNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get length() {
|
|
||||||
return this.queue.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
get isProcessing() {
|
|
||||||
return this.processing;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Singleton instance
|
|
||||||
const requestQueue = new RequestQueue();
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// Section 3: Drive API Client
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -214,11 +162,11 @@ async function queryDocuments(options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// Section 4: Request Handling & Routing
|
// Section 3: Request Handling & Routing
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle sitemap generation request (wrapped in FIFO queue)
|
* Handle sitemap generation request
|
||||||
*/
|
*/
|
||||||
async function handleSitemapRequest(res, requestId) {
|
async function handleSitemapRequest(res, requestId) {
|
||||||
try {
|
try {
|
||||||
@@ -275,9 +223,9 @@ async function handleSitemapRequest(res, requestId) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle sitemap route with FIFO queue (sequential processing)
|
// Handle sitemap route
|
||||||
if (routeResult.route === "sitemap") {
|
if (routeResult.route === "sitemap") {
|
||||||
await requestQueue.enqueue(() => handleSitemapRequest(res, requestId));
|
await handleSitemapRequest(res, requestId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user