Skip to content

Commit

Permalink
Tweak regex for trailing slashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed May 13, 2021
1 parent f21734f commit bd4cea5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions oada/services/write-handler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ export function handleReq(req: WriteRequest): Promise<WriteResponse> {
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']);
Expand All @@ -180,10 +180,10 @@ export function handleReq(req: WriteRequest): Promise<WriteResponse> {
}
}
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']);
Expand All @@ -194,10 +194,10 @@ export function handleReq(req: WriteRequest): Promise<WriteResponse> {
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) {
Expand All @@ -208,7 +208,8 @@ export function handleReq(req: WriteRequest): Promise<WriteResponse> {

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(/(?<!\/)\/+$/, '')
); /* comment so syntax highlighting is ok */
let method = resources.putResource;
changeType = 'merge';
Expand Down

0 comments on commit bd4cea5

Please sign in to comment.