Faster web UI: only changed lists reloaded, icon cache kept, storage usage cached

- Web UI: loadLists(only) fetches only the lists an action changed; saving a
  bitmap, icon or font also reloads the pages that use it
- Icons: a save or delete forgets only that name and updates the name list in
  place instead of listing the directory again
- Storage usage cached until a store writes or deletes a file (at most 60 s):
  /api/status 0.6 s -> 0.08 s
- Version 2.19.2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-10-22 00:13:46 +02:00
1 parent 72a193130e
commit 41af2944bc
8 files changed
+120 -35

No files matched your search

+44 -7
View File
@@ -62,6 +62,14 @@ struct CachedIcon
static std::map<String, CachedIcon> cache;
static const size_t CACHE_MAX = 128;
// After a save or delete: only this name (in any case, as it was looked up) is read again.
// Clearing everything made the next list of all icons read each one again (7 s).
static void forget(const char *name)
{
for (auto it = cache.begin(); it != cache.end();)
it = it->first.equalsIgnoreCase(name) ? cache.erase(it) : std::next(it);
}
// Full: first forget the missing names, only then the icons
static void makeRoom()
{
@@ -97,10 +105,35 @@ void iconStoreBegin()
}
}
// The sorted names, kept until an icon is saved or deleted (listing takes about a second)
// The sorted names, listed once (about a second) and then kept up to date
static std::vector<String> listed;
static bool listed_valid = false;
static bool nameBefore(const String &a, const String &b)
{
return strcasecmp(a.c_str(), b.c_str()) < 0;
}
static void listAdd(const char *name)
{
// It may replace a built-in one in another case: list again
if (builtinIconName(name))
listed_valid = false;
if (!listed_valid || std::find(listed.begin(), listed.end(), String(name)) != listed.end())
return;
listed.insert(std::lower_bound(listed.begin(), listed.end(), String(name), nameBefore), String(name));
}
static void listRemove(const char *name)
{
// A built-in one stays in the list (from the firmware): list again
if (builtinIconName(name))
listed_valid = false;
auto it = std::find(listed.begin(), listed.end(), String(name));
if (listed_valid && it != listed.end())
listed.erase(it);
}
std::vector<String> listIcons()
{
if (listed_valid)
@@ -109,8 +142,7 @@ std::vector<String> listIcons()
for (const BuiltinIcon &b : BUILTIN) // not stored (no storage)
if (std::none_of(names.begin(), names.end(), [&b](const String &n) { return strcasecmp(n.c_str(), b.name) == 0; }))
names.push_back(b.name);
std::sort(names.begin(), names.end(),
[](const String &a, const String &b) { return strcasecmp(a.c_str(), b.c_str()) < 0; });
std::sort(names.begin(), names.end(), nameBefore);
listed = names;
listed_valid = true;
return names;
@@ -194,16 +226,20 @@ const char *saveIcon(const char *name, const Icon &icon)
bool ok = file.write(size, 2) == 2 && file.write(icon.data, bytes) == bytes;
file.close();
revision++;
cache.clear();
listed_valid = false;
bitmapStorageChanged();
forget(name);
if (!ok)
{
listed_valid = false;
LittleFS.remove(path(name)); // not half an icon
count = -1;
return "Storage full";
}
if (is_new)
{
count++;
listAdd(name);
}
return nullptr;
}
@@ -216,7 +252,8 @@ const char *deleteIcon(const char *name)
if (count > 0)
count--;
revision++;
cache.clear();
listed_valid = false;
bitmapStorageChanged();
forget(name);
listRemove(name);
return nullptr;
}