summaryrefslogtreecommitdiff
path: root/svx/source/tbxctrls/StylesPreviewWindow.cxx
diff options
context:
space:
mode:
authorCaolán McNamara <caolan.mcnamara@collabora.com>2023-06-07 20:43:12 +0100
committerCaolán McNamara <caolan.mcnamara@collabora.com>2023-06-09 17:52:23 +0200
commitaae8841e2057d522b3cae7b5792ae75cc8d6b5b4 (patch)
treeba256bd7d3c0f9a56ed014536b355a6a7f2b5f5b /svx/source/tbxctrls/StylesPreviewWindow.cxx
parent6fc48879f8347a53a5ef1bf801fab831be3310f2 (diff)
Related: cool#6511 hold json preview cache longer
due to oddities related to tdf155720 the notebookbar the cache is hooked to can be torn down and replaced if the 1st session is interacted with while multiple other users join. So count goes to 0 just at the wrong time to trigger throwing away the cache and forcing regeneration. An Idle doesn't suffice here. https: //github.com/CollaboraOnline/online/issues/6511 Change-Id: I148c99115fc497e34bf8920b6f59adc47605b8a1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152720 Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'svx/source/tbxctrls/StylesPreviewWindow.cxx')
-rw-r--r--svx/source/tbxctrls/StylesPreviewWindow.cxx41
1 files changed, 36 insertions, 5 deletions
diff --git a/svx/source/tbxctrls/StylesPreviewWindow.cxx b/svx/source/tbxctrls/StylesPreviewWindow.cxx
index 53a8f14511a9..c5215cba4a6d 100644
--- a/svx/source/tbxctrls/StylesPreviewWindow.cxx
+++ b/svx/source/tbxctrls/StylesPreviewWindow.cxx
@@ -68,35 +68,66 @@ namespace
{
class StylePreviewCache
{
+private:
+ class JsonStylePreviewCacheClear final : public Timer
+ {
+ public:
+ JsonStylePreviewCacheClear()
+ : Timer("Json Style Preview Cache clear callback")
+ {
+ // a generous 30 secs
+ SetTimeout(30000);
+ SetStatic();
+ }
+ virtual void Invoke() override { StylePreviewCache::gJsonStylePreviewCache.clear(); }
+ };
+
static std::map<OUString, VclPtr<VirtualDevice>> gStylePreviewCache;
static std::map<OUString, OString> gJsonStylePreviewCache;
static int gStylePreviewCacheClients;
+ static JsonStylePreviewCacheClear gJsonIdleClear;
public:
static std::map<OUString, VclPtr<VirtualDevice>>& Get() { return gStylePreviewCache; }
static std::map<OUString, OString>& GetJson() { return gJsonStylePreviewCache; }
- static void ClearCache()
+ static void ClearCache(bool bHard)
{
for (auto& aPreview : gStylePreviewCache)
aPreview.second.disposeAndClear();
gStylePreviewCache.clear();
- gJsonStylePreviewCache.clear();
+ if (bHard)
+ {
+ StylePreviewCache::gJsonStylePreviewCache.clear();
+ gJsonIdleClear.Stop();
+ }
+ else
+ {
+ // tdf#155720 don't immediately clear the json representation
+ gJsonIdleClear.Start();
+ }
+ }
+
+ static void RegisterClient()
+ {
+ if (!gStylePreviewCacheClients)
+ gJsonIdleClear.Stop();
+ gStylePreviewCacheClients++;
}
- static void RegisterClient() { gStylePreviewCacheClients++; }
static void UnregisterClient()
{
gStylePreviewCacheClients--;
if (!gStylePreviewCacheClients)
- ClearCache();
+ ClearCache(false);
}
};
std::map<OUString, VclPtr<VirtualDevice>> StylePreviewCache::gStylePreviewCache;
std::map<OUString, OString> StylePreviewCache::gJsonStylePreviewCache;
int StylePreviewCache::gStylePreviewCacheClients;
+StylePreviewCache::JsonStylePreviewCacheClear StylePreviewCache::gJsonIdleClear;
}
StyleStatusListener::StyleStatusListener(
@@ -143,7 +174,7 @@ StylePoolChangeListener::~StylePoolChangeListener()
void StylePoolChangeListener::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
{
if (rHint.GetId() == SfxHintId::StyleSheetModified)
- StylePreviewCache::ClearCache();
+ StylePreviewCache::ClearCache(true);
m_pPreviewControl->RequestStylesListUpdate();
}