From c79e53db80744a430616b5d8d13ea0313d28024c Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 25 Jul 2022 12:17:40 +0100 Subject: [PATCH 1/3] Ignore 409s in write-through cache --- packages/backend-core/src/cache/writethrough.ts | 7 +++---- packages/backend-core/src/logging.ts | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/backend-core/src/cache/writethrough.ts b/packages/backend-core/src/cache/writethrough.ts index e11ca0acaa..701351d75b 100644 --- a/packages/backend-core/src/cache/writethrough.ts +++ b/packages/backend-core/src/cache/writethrough.ts @@ -1,5 +1,6 @@ import BaseCache from "./base" import { getWritethroughClient } from "../redis/init" +import { logInfo } from "../logging" const DEFAULT_WRITE_RATE_MS = 10000 let CACHE: BaseCache | null = null @@ -51,10 +52,8 @@ export async function put( if (err.status !== 409) { throw err } else { - // get the rev, update over it - this is risky, may change in future - const readDoc = await db.get(doc._id) - doc._rev = readDoc._rev - await writeDb(doc) + // Swallow 409s but log them + logInfo(`Ignoring conflict in write-through cache`) } } } diff --git a/packages/backend-core/src/logging.ts b/packages/backend-core/src/logging.ts index 68c3307b2f..fcfa04bbb9 100644 --- a/packages/backend-core/src/logging.ts +++ b/packages/backend-core/src/logging.ts @@ -15,6 +15,11 @@ export function logAlert(message: string, e?: any) { console.error(`bb-alert: ${message} ${errorJson}`) } +export function logInfo(message: string) { + console.warn(`bb-info: ${message}`) +} + export default { logAlert, + logInfo, } From a0380d7b8001381d5976c9a2a4238eb675925283 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 25 Jul 2022 12:22:27 +0100 Subject: [PATCH 2/3] Use log rather than warn for logInfo --- packages/backend-core/src/logging.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend-core/src/logging.ts b/packages/backend-core/src/logging.ts index fcfa04bbb9..63bdc092e9 100644 --- a/packages/backend-core/src/logging.ts +++ b/packages/backend-core/src/logging.ts @@ -16,7 +16,7 @@ export function logAlert(message: string, e?: any) { } export function logInfo(message: string) { - console.warn(`bb-info: ${message}`) + console.log(`bb-info: ${message}`) } export default { From d63c547dd6fb0cfc58670fe5cfdf51acf633078c Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 25 Jul 2022 12:23:30 +0100 Subject: [PATCH 3/3] Use warn rather than info when notifying about ignored conflicts --- packages/backend-core/src/cache/writethrough.ts | 4 ++-- packages/backend-core/src/logging.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/backend-core/src/cache/writethrough.ts b/packages/backend-core/src/cache/writethrough.ts index 701351d75b..ec6b1604c8 100644 --- a/packages/backend-core/src/cache/writethrough.ts +++ b/packages/backend-core/src/cache/writethrough.ts @@ -1,6 +1,6 @@ import BaseCache from "./base" import { getWritethroughClient } from "../redis/init" -import { logInfo } from "../logging" +import { logWarn } from "../logging" const DEFAULT_WRITE_RATE_MS = 10000 let CACHE: BaseCache | null = null @@ -53,7 +53,7 @@ export async function put( throw err } else { // Swallow 409s but log them - logInfo(`Ignoring conflict in write-through cache`) + logWarn(`Ignoring conflict in write-through cache`) } } } diff --git a/packages/backend-core/src/logging.ts b/packages/backend-core/src/logging.ts index 63bdc092e9..8eda15ac79 100644 --- a/packages/backend-core/src/logging.ts +++ b/packages/backend-core/src/logging.ts @@ -15,11 +15,11 @@ export function logAlert(message: string, e?: any) { console.error(`bb-alert: ${message} ${errorJson}`) } -export function logInfo(message: string) { - console.log(`bb-info: ${message}`) +export function logWarn(message: string) { + console.warn(`bb-warn: ${message}`) } export default { logAlert, - logInfo, + logWarn, }