From 42ec28a642a600120f76863869813b19f2473c93 Mon Sep 17 00:00:00 2001 From: jj Date: Fri, 1 Nov 2024 14:58:04 +0000 Subject: [PATCH] api/cookie: update cookies value-by-value in manager --- api/src/processing/cookie/cookie.js | 15 ++++++++++----- api/src/processing/cookie/manager.js | 13 +++++++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/api/src/processing/cookie/cookie.js b/api/src/processing/cookie/cookie.js index 5a3f6dcd..1d9636d5 100644 --- a/api/src/processing/cookie/cookie.js +++ b/api/src/processing/cookie/cookie.js @@ -4,13 +4,18 @@ export default class Cookie { constructor(input) { assert(typeof input === 'object'); this._values = {}; - this.set(input) + + for (const [ k, v ] of Object.entries(input)) + this.set(k, v); } - set(values) { - Object.entries(values).forEach( - ([ key, value ]) => this._values[key] = value - ) + set(key, value) { + const old = this._values[key]; + if (old === value) + return false; + + this._values[key] = value; + return true; } unset(keys) { diff --git a/api/src/processing/cookie/manager.js b/api/src/processing/cookie/manager.js index eb25adbb..074d0045 100644 --- a/api/src/processing/cookie/manager.js +++ b/api/src/processing/cookie/manager.js @@ -42,8 +42,17 @@ export function getCookie(service) { } export function updateCookieValues(cookie, values) { - cookie.set(values); - if (Object.keys(values).length) dirty = true + let changed = false; + + for (const [ key, value ] of Object.entries(values)) { + changed ||= cookie.set(key, value); + } + + if (changed) { + dirty = true; + } + + return changed; } export function updateCookie(cookie, headers) {