From 045ec83d81705c7c4e0fd6fd86f7decd18e31ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 4 Aug 2022 20:41:57 +0200 Subject: [PATCH] CustomCategory: cache categories --- src/customCategory.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/customCategory.js b/src/customCategory.js index 06ec155d..361e2414 100644 --- a/src/customCategory.js +++ b/src/customCategory.js @@ -5,6 +5,8 @@ const md5 = require('md5') const OpenStreetBrowserLoader = require('./OpenStreetBrowserLoader') +const cache = {} + class CustomCategoryRepository { constructor () { } @@ -17,6 +19,10 @@ class CustomCategoryRepository { } getCategory (id, options, callback) { + if (id in cache) { + return callback(null, yaml.load(cache[id])) + } + ajax('customCategory', { id }, (result) => { callback(null, yaml.load(result)) }) @@ -75,15 +81,16 @@ class CustomCategory { applyContent (content) { this.content = content - const id = 'custom/' + md5(content) + const id = md5(content) const data = yaml.load(content) + cache[id] = content if (this.category) { this.category.remove() this.category = null } - OpenStreetBrowserLoader.getCategoryFromData(id, {}, data, (err, category) => { + OpenStreetBrowserLoader.getCategoryFromData('custom/' + id, {}, data, (err, category) => { if (err) { return global.alert(err) }