From bd4cea5329462b9d79238ee27eeab637b1c98830 Mon Sep 17 00:00:00 2001 From: Alex Layton Date: Thu, 13 May 2021 19:51:27 -0400 Subject: [PATCH] Tweak regex for trailing slashes. --- oada/services/write-handler/src/index.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/oada/services/write-handler/src/index.ts b/oada/services/write-handler/src/index.ts index 32b848e2..6a6d25d7 100644 --- a/oada/services/write-handler/src/index.ts +++ b/oada/services/write-handler/src/index.ts @@ -168,10 +168,10 @@ export function handleReq(req: WriteRequest): Promise { trace('FIRST BODY %O', body); trace('doUpsert %d', Date.now() / 1000 - beforeUpsert); if (req['if-match']) { - const rev = (await resources.getResource( + const rev = ((await resources.getResource( req['resource_id'], '_rev' - )) as unknown as number; + )) as unknown) as number; if (req['if-match'] !== rev) { error(rev); error(req['if-match']); @@ -180,10 +180,10 @@ export function handleReq(req: WriteRequest): Promise { } } if (req['if-none-match']) { - const rev = (await resources.getResource( + const rev = ((await resources.getResource( req['resource_id'], '_rev' - )) as unknown as number; + )) as unknown) as number; if (req['if-none-match'].includes(rev)) { error(rev); error(req['if-none-match']); @@ -194,10 +194,10 @@ export function handleReq(req: WriteRequest): Promise { const beforeCacheRev = Date.now() / 1000; let cacheRev = cache.get(req['resource_id']); if (!cacheRev) { - cacheRev = (await resources.getResource( + cacheRev = ((await resources.getResource( req['resource_id'], '_rev' - )) as unknown as number; + )) as unknown) as number; } if (req.rev) { if (cacheRev !== req.rev) { @@ -208,7 +208,8 @@ export function handleReq(req: WriteRequest): Promise { const beforeDeletePartial = Date.now() / 1000; let path = pointer.parse( - req['path_leftover'].replace(/\/*$/, '') + // The negative lookbehind may look useless but it helps performance. + req['path_leftover'].replace(/(?