Public Access
Page names kept in RAM: /api/pages 1.8 s -> 1.05 s
Measured on the display with 16 pages: listing the directory took 350 ms, and every loadPage() first asked LittleFS whether the file exists (26 ms each) before opening it (25 ms) and reading it (11 ms); drawing all previews took only 29 ms. The names of the stored pages are now kept until a page is saved or deleted, and storedPage() looks there instead of calling exists(). Version 2.19.1, tested on the display over OTA (save, list, delete). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0166d0ee46
commit
72a193130e
2 files changed
+31
-6
No files matched your search
+1
-1
@@ -118,7 +118,7 @@ const uint32_t SETUP_AP_DELAY = 20000; // open the AP when WiFi fails thi
|
|||||||
const uint32_t WIFI_CONNECT_TIMEOUT = 30000;
|
const uint32_t WIFI_CONNECT_TIMEOUT = 30000;
|
||||||
const uint32_t WIFI_RESTART_TIME = 10UL * 60 * 1000;
|
const uint32_t WIFI_RESTART_TIME = 10UL * 60 * 1000;
|
||||||
|
|
||||||
#define FIRMWARE_VERSION "2.19.0"
|
#define FIRMWARE_VERSION "2.19.1"
|
||||||
|
|
||||||
// Home Assistant device id (do not change: Home Assistant's entities are linked to it)
|
// Home Assistant device id (do not change: Home Assistant's entities are linked to it)
|
||||||
const uint8_t HA_DEVICE_ID[] = {0x34, 0x86, 0x5d, 0x3a, 0x08, 0x28};
|
const uint8_t HA_DEVICE_ID[] = {0x34, 0x86, 0x5d, 0x3a, 0x08, 0x28};
|
||||||
|
|||||||
@@ -25,9 +25,29 @@ static String path(const char *name)
|
|||||||
return String(DIR) + "/" + name + EXTENSION;
|
return String(DIR) + "/" + name + EXTENSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The names of the stored pages, kept until a page is saved or deleted: listing the
|
||||||
|
// directory takes about 350 ms with 16 pages, and each exists() about 25 ms
|
||||||
|
static std::vector<String> names;
|
||||||
|
static bool names_valid = false;
|
||||||
|
|
||||||
|
static const std::vector<String> &storedPageNames()
|
||||||
|
{
|
||||||
|
if (!names_valid)
|
||||||
|
{
|
||||||
|
names = bitmapStorageAvailable() ? storedNames(DIR, EXTENSION) : std::vector<String>();
|
||||||
|
names_valid = true;
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
static bool storedPage(const char *name)
|
static bool storedPage(const char *name)
|
||||||
{
|
{
|
||||||
return bitmapStorageAvailable() && validBitmapName(name) && LittleFS.exists(path(name));
|
if (!bitmapStorageAvailable() || !validBitmapName(name))
|
||||||
|
return false;
|
||||||
|
for (const String &stored : storedPageNames())
|
||||||
|
if (stored == name) // like exists(): the file names are case-sensitive
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pageStoreBegin()
|
void pageStoreBegin()
|
||||||
@@ -48,7 +68,7 @@ std::vector<PageInfo> listPages()
|
|||||||
for (int i = 0; i < builtinPageCount(); i++)
|
for (int i = 0; i < builtinPageCount(); i++)
|
||||||
if (!storedPage(builtinPageName(i)))
|
if (!storedPage(builtinPageName(i)))
|
||||||
list.push_back({builtinPageName(i), true, false});
|
list.push_back({builtinPageName(i), true, false});
|
||||||
for (const String &name : storedNames(DIR, EXTENSION))
|
for (const String &name : storedPageNames())
|
||||||
list.push_back({name, false, builtinPageName(name.c_str()) != nullptr});
|
list.push_back({name, false, builtinPageName(name.c_str()) != nullptr});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@@ -99,7 +119,7 @@ const char *savePage(const char *name, const DynamicPage &page)
|
|||||||
return error;
|
return error;
|
||||||
if (!bitmapStorageAvailable())
|
if (!bitmapStorageAvailable())
|
||||||
return "No storage (install the new flash layout over USB, see README)";
|
return "No storage (install the new flash layout over USB, see README)";
|
||||||
if (!LittleFS.exists(path(name)) && storedNames(DIR, EXTENSION).size() >= (size_t)MAX_PAGES)
|
if (!storedPage(name) && storedPageNames().size() >= (size_t)MAX_PAGES)
|
||||||
return "Too many pages, delete some first";
|
return "Too many pages, delete some first";
|
||||||
|
|
||||||
StoredPage *stored = new StoredPage;
|
StoredPage *stored = new StoredPage;
|
||||||
@@ -112,6 +132,7 @@ const char *savePage(const char *name, const DynamicPage &page)
|
|||||||
file.close();
|
file.close();
|
||||||
delete stored;
|
delete stored;
|
||||||
revision++;
|
revision++;
|
||||||
|
names_valid = false;
|
||||||
return ok ? nullptr : "Could not write the file (storage full?)";
|
return ok ? nullptr : "Could not write the file (storage full?)";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +142,9 @@ const char *deletePage(const char *name)
|
|||||||
return "Built-in pages can't be deleted";
|
return "Built-in pages can't be deleted";
|
||||||
if (!storedPage(name))
|
if (!storedPage(name))
|
||||||
return "Page not found";
|
return "Page not found";
|
||||||
if (!LittleFS.remove(path(name)))
|
bool removed = LittleFS.remove(path(name));
|
||||||
|
names_valid = false;
|
||||||
|
if (!removed)
|
||||||
return "Could not delete the file";
|
return "Could not delete the file";
|
||||||
revision++;
|
revision++;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -132,7 +155,9 @@ template <typename F> static String findPage(F uses)
|
|||||||
{
|
{
|
||||||
DynamicPage *page = new DynamicPage;
|
DynamicPage *page = new DynamicPage;
|
||||||
String found;
|
String found;
|
||||||
for (const String &name : storedNames(DIR, EXTENSION))
|
// A copy: loadPage() may list the directory again
|
||||||
|
std::vector<String> list = storedPageNames();
|
||||||
|
for (const String &name : list)
|
||||||
if (loadPage(name.c_str(), *page) && uses(*page))
|
if (loadPage(name.c_str(), *page) && uses(*page))
|
||||||
{
|
{
|
||||||
found = name;
|
found = name;
|
||||||
|
|||||||
Reference in new issue
Block a user