Skip to content

Commit 030366a

Browse files
committed
changes from testing scripts in local environment
1 parent f75d04e commit 030366a

3 files changed

Lines changed: 20 additions & 35 deletions

File tree

cache/__tests__/cache-metrics-worst-case.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -850,9 +850,18 @@ test_history_endpoint() {
850850
# Wait for object to be available
851851
sleep 2
852852

853+
# Extract just the ID portion for the history endpoint
854+
local obj_id=$(echo "$test_id" | sed 's|.*/||')
855+
856+
# Skip history test if object creation failed
857+
if [ -z "$obj_id" ] || [ "$obj_id" == "null" ]; then
858+
log_warning "Skipping history test - object creation failed"
859+
return
860+
fi
861+
853862
# Get the full object and update to create history
854863
local full_object=$(curl -s "$test_id" 2>/dev/null)
855-
local update_body=$(echo "$full_object" | jq '.version = 2' 2>/dev/null)
864+
local update_body=$(echo "$full_object" | jq '. + {version: 2}' 2>/dev/null)
856865

857866
curl -s -X PUT "${API_BASE}/api/update" \
858867
-H "Content-Type: application/json" \
@@ -862,9 +871,6 @@ test_history_endpoint() {
862871
sleep 2
863872
clear_cache
864873

865-
# Extract just the ID portion for the history endpoint
866-
local obj_id=$(echo "$test_id" | sed 's|.*/||')
867-
868874
# Test history with cold cache
869875
log_info "Testing history with cold cache..."
870876
local result=$(measure_endpoint "${API_BASE}/history/${obj_id}" "GET" "" "Get object history")

cache/__tests__/cache-metrics.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,18 @@ test_history_endpoint() {
869869
# Wait for object to be available
870870
sleep 2
871871

872+
# Extract just the ID portion for the history endpoint
873+
local obj_id=$(echo "$test_id" | sed 's|.*/||')
874+
875+
# Skip history test if object creation failed
876+
if [ -z "$obj_id" ] || [ "$obj_id" == "null" ]; then
877+
log_warning "Skipping history test - object creation failed"
878+
return
879+
fi
880+
872881
# Get the full object and update to create history
873882
local full_object=$(curl -s "$test_id" 2>/dev/null)
874-
local update_body=$(echo "$full_object" | jq '.version = 2' 2>/dev/null)
883+
local update_body=$(echo "$full_object" | jq '. + {version: 2}' 2>/dev/null)
875884

876885
curl -s -X PUT "${API_BASE}/api/update" \
877886
-H "Content-Type: application/json" \
@@ -881,9 +890,6 @@ test_history_endpoint() {
881890
sleep 2
882891
clear_cache
883892

884-
# Extract just the ID portion for the history endpoint
885-
local obj_id=$(echo "$test_id" | sed 's|.*/||')
886-
887893
# Test history with cold cache
888894
log_info "Testing history with cold cache..."
889895
local result=$(measure_endpoint "${API_BASE}/history/${obj_id}" "GET" "" "Get object history")

cache/middleware.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,6 @@ const cacheSince = (req, res, next) => {
267267
* Invalidates cache entries when objects are created, updated, or deleted
268268
*/
269269
const invalidateCache = (req, res, next) => {
270-
console.log(`[CACHE INVALIDATE] Middleware triggered for ${req.method} ${req.path}`)
271-
272270
// Store original response methods
273271
const originalJson = res.json.bind(res)
274272
const originalSend = res.send.bind(res)
@@ -281,23 +279,18 @@ const invalidateCache = (req, res, next) => {
281279
const performInvalidation = (data) => {
282280
// Prevent duplicate invalidation
283281
if (invalidationPerformed) {
284-
console.log('[CACHE INVALIDATE] Skipping duplicate invalidation')
285282
return
286283
}
287284
invalidationPerformed = true
288285

289-
console.log(`[CACHE INVALIDATE] Response handler called with status ${res.statusCode}`)
290-
291286
// Only invalidate on successful write operations
292287
if (res.statusCode >= 200 && res.statusCode < 300) {
293288
// Use originalUrl to get the full path (req.path only shows the path within the mounted router)
294289
const path = req.originalUrl || req.path
295-
console.log(`[CACHE INVALIDATE] Processing path: ${path} (originalUrl: ${req.originalUrl}, path: ${req.path})`)
296290

297291
// Determine what to invalidate based on the operation
298292
if (path.includes('/create') || path.includes('/bulkCreate')) {
299293
// For creates, use smart invalidation based on the created object's properties
300-
console.log('[CACHE INVALIDATE] Create operation detected - using smart cache invalidation')
301294

302295
// Extract the created object(s)
303296
const createdObjects = path.includes('/bulkCreate')
@@ -314,17 +307,11 @@ const invalidateCache = (req, res, next) => {
314307
// This ensures queries matching this object will be refreshed
315308
cache.invalidateByObject(obj, invalidatedKeys)
316309
}
317-
318-
console.log(`[CACHE INVALIDATE] Invalidated ${invalidatedKeys.size} cache entries using smart invalidation`)
319-
if (invalidatedKeys.size > 0) {
320-
console.log(`[CACHE INVALIDATE] Invalidated keys: ${Array.from(invalidatedKeys).slice(0, 5).join(', ')}${invalidatedKeys.size > 5 ? '...' : ''}`)
321-
}
322310
}
323311
else if (path.includes('/update') || path.includes('/patch') ||
324312
path.includes('/set') || path.includes('/unset') ||
325313
path.includes('/overwrite') || path.includes('/bulkUpdate')) {
326314
// For updates, use smart invalidation based on the updated object
327-
console.log('[CACHE INVALIDATE] Update operation detected - using smart cache invalidation')
328315

329316
// Extract updated object (response may contain new_obj_state or the object directly)
330317
const updatedObject = data?.new_obj_state ?? data
@@ -360,20 +347,13 @@ const invalidateCache = (req, res, next) => {
360347
const versionIds = [objIdShort, previousId, primeId].filter(id => id && id !== 'root').join('|')
361348
const historyPattern = new RegExp(`^(history|since):(${versionIds})`)
362349
const historyCount = cache.invalidate(historyPattern)
363-
364-
console.log(`[CACHE INVALIDATE] Invalidated ${invalidatedKeys.size} cache entries (${historyCount} history/since for chain: ${versionIds})`)
365-
if (invalidatedKeys.size > 0) {
366-
console.log(`[CACHE INVALIDATE] Invalidated keys: ${Array.from(invalidatedKeys).slice(0, 5).join(', ')}${invalidatedKeys.size > 5 ? '...' : ''}`)
367-
}
368350
} else {
369351
// Fallback to broad invalidation if we can't extract the object
370-
console.log('[CACHE INVALIDATE] Update operation (fallback - no object data)')
371352
cache.invalidate(/^(query|search|searchPhrase|id|history|since):/)
372353
}
373354
}
374355
else if (path.includes('/delete')) {
375356
// For deletes, use smart invalidation based on the deleted object
376-
console.log('[CACHE INVALIDATE] Delete operation detected - using smart cache invalidation')
377357

378358
// Get the deleted object from res.locals (set by delete controller before deletion)
379359
const deletedObject = res.locals.deletedObject
@@ -408,20 +388,13 @@ const invalidateCache = (req, res, next) => {
408388
const versionIds = [objIdShort, previousId, primeId].filter(id => id && id !== 'root').join('|')
409389
const historyPattern = new RegExp(`^(history|since):(${versionIds})`)
410390
const historyCount = cache.invalidate(historyPattern)
411-
412-
console.log(`[CACHE INVALIDATE] Invalidated ${invalidatedKeys.size} cache entries (${historyCount} history/since for chain: ${versionIds})`)
413-
if (invalidatedKeys.size > 0) {
414-
console.log(`[CACHE INVALIDATE] Invalidated keys: ${Array.from(invalidatedKeys).slice(0, 5).join(', ')}${invalidatedKeys.size > 5 ? '...' : ''}`)
415-
}
416391
} else {
417392
// Fallback to broad invalidation if we can't extract the object
418-
console.log('[CACHE INVALIDATE] Delete operation (fallback - no object data from res.locals)')
419393
cache.invalidate(/^(query|search|searchPhrase|id|history|since):/)
420394
}
421395
}
422396
else if (path.includes('/release')) {
423397
// Release creates a new version, invalidate all including history/since
424-
console.log('[CACHE INVALIDATE] Cache INVALIDATE: release operation')
425398
cache.invalidate(/^(query|search|searchPhrase|id|history|since):/)
426399
}
427400
}

0 commit comments

Comments
 (0)