From b25b3e3c6167506cfbb5efc3009d51531a6e342e Mon Sep 17 00:00:00 2001 From: Magnus Gille Date: Sat, 10 Jan 2026 11:35:30 -0800 Subject: [PATCH] Key the CloudDB cache by hostname and add a button to clear the cache (#4794) Using the new go125 server for testing purposes [publish binaries] --- src/Cloud/CloudDBChart.cpp | 37 +++++++++++++++++++++++++++++++-- src/Cloud/CloudDBChart.h | 3 +++ src/Cloud/CloudDBUserMetric.cpp | 4 ++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/Cloud/CloudDBChart.cpp b/src/Cloud/CloudDBChart.cpp index 1e7761d0e..7c5d708d1 100644 --- a/src/Cloud/CloudDBChart.cpp +++ b/src/Cloud/CloudDBChart.cpp @@ -50,10 +50,10 @@ CloudDBChartClient::CloudDBChartClient() g_nam = new QNetworkAccessManager(this); QDir cacheDir(QStandardPaths::standardLocations(QStandardPaths::AppLocalDataLocation).at(0)); cacheDir.cdUp(); - g_cacheDir = QString(cacheDir.absolutePath()+"/GoldenCheetahCloudDB"); + g_cacheDir = QString(cacheDir.absolutePath()+"/GoldenCheetahCloudDB/" + QString(QT_STRINGIFY(GC_CLOUD_DB_APP_NAME))); QDir newCacheDir(g_cacheDir); if (!newCacheDir.exists()) { - cacheDir.mkdir("GoldenCheetahCloudDB"); + newCacheDir.mkpath(g_cacheDir); } // general handling for sslErrors @@ -237,6 +237,15 @@ CloudDBChartClient::getAllChartHeader(QList* header) { return request_ok; } +bool +CloudDBChartClient::clearAllCache() { + QDir cacheDir(g_cacheDir); + if (cacheDir.exists()) { + return cacheDir.removeRecursively(); + } + return true; +} + // // Trap SSL errors @@ -449,20 +458,24 @@ CloudDBChartListDialog::CloudDBChartListDialog() : const_stepSize(5) showing = new QLabel; showingTextTemplate = tr("Showing %1 to %2 of %3 charts for %4 / Total uploaded %5"); resetToStart = new QPushButton(tr("First")); + clearCacheButton = new QPushButton(tr("Clear Cache")); nextSet = new QPushButton(tr("Next %1").arg(QString::number(const_stepSize))); prevSet = new QPushButton(tr("Prev %1").arg(QString::number(const_stepSize))); resetToStart->setEnabled(true); nextSet->setDefault(true); + clearCacheButton->setEnabled(true); nextSet->setEnabled(true); prevSet->setEnabled(true); connect(resetToStart, SIGNAL(clicked()), this, SLOT(resetToStartClicked())); connect(nextSet, SIGNAL(clicked()), this, SLOT(nextSetClicked())); connect(prevSet, SIGNAL(clicked()), this, SLOT(prevSetClicked())); + connect(clearCacheButton, &QPushButton::clicked, this, &CloudDBChartListDialog::clearCacheClicked); showingLayout = new QHBoxLayout; showingLayout->addWidget(showing); showingLayout->addStretch(); + showingLayout->addWidget(clearCacheButton); showingLayout->addWidget(resetToStart); showingLayout->addWidget(prevSet); showingLayout->addWidget(nextSet); @@ -659,6 +672,7 @@ CloudDBChartListDialog::updateCurrentPresets(int index, int count) { prevSet->setEnabled(false); closeUserGetButton->setEnabled(false); addAndCloseUserGetButton->setEnabled(false); + clearCacheButton->setEnabled(false); curationStateCombo->setEnabled(false); ownChartsOnly->setEnabled(false); textFilterApply->setEnabled(false); @@ -755,8 +769,10 @@ CloudDBChartListDialog::updateCurrentPresets(int index, int count) { resetToStart->setEnabled(true); nextSet->setEnabled(true); prevSet->setEnabled(true); + clearCacheButton->setEnabled(true); closeUserGetButton->setEnabled(true); addAndCloseUserGetButton->setEnabled(true); + clearCacheButton->setEnabled(true); curationStateCombo->setEnabled(true); ownChartsOnly->setEnabled(true); textFilterApply->setEnabled(true); @@ -777,6 +793,23 @@ CloudDBChartListDialog::updateCurrentPresets(int index, int count) { } +void +CloudDBChartListDialog::clearCacheClicked() { + // clear the physical cache + g_client->clearAllCache(); + + // force a refresh from Network + CloudDBHeader::setChartHeaderStale(true); + + // reset UI + g_currentIndex = 0; + if (CloudDBHeader::isStaleChartHeader()) { + if (!refreshStaleChartHeader()) return; + CloudDBHeader::setChartHeaderStale(false); + } + applyAllFilters(); +} + void CloudDBChartListDialog::setVisibleButtonsForRole() { if (g_role == CloudDBCommon::UserEdit) { diff --git a/src/Cloud/CloudDBChart.h b/src/Cloud/CloudDBChart.h index 9e073c431..4ed7e2745 100644 --- a/src/Cloud/CloudDBChart.h +++ b/src/Cloud/CloudDBChart.h @@ -63,6 +63,7 @@ public: bool curateChartByID(qint64 id, bool newStatus); void incrementDownloadCounterByID(qint64 id); bool getAllChartHeader(QList* header); + bool clearAllCache(); bool sslLibMissing() { return noSSLlib; } @@ -133,6 +134,7 @@ private slots: void resetToStartClicked(); void nextSetClicked(); void prevSetClicked(); + void clearCacheClicked(); void ownChartsToggled(bool); void toggleTextFilterApply(); void curationStateFilterChanged(int); @@ -172,6 +174,7 @@ private: QPushButton *resetToStart; QPushButton *nextSet; QPushButton *prevSet; + QPushButton *clearCacheButton; QCheckBox *ownChartsOnly; QComboBox *curationStateCombo; QComboBox *langCombo; diff --git a/src/Cloud/CloudDBUserMetric.cpp b/src/Cloud/CloudDBUserMetric.cpp index 7ecc19c54..bc5e2bba8 100644 --- a/src/Cloud/CloudDBUserMetric.cpp +++ b/src/Cloud/CloudDBUserMetric.cpp @@ -43,10 +43,10 @@ CloudDBUserMetricClient::CloudDBUserMetricClient() g_nam = new QNetworkAccessManager(this); QDir cacheDir(QStandardPaths::standardLocations(QStandardPaths::AppLocalDataLocation).at(0)); cacheDir.cdUp(); - g_cacheDir = QString(cacheDir.absolutePath()+"/GoldenCheetahCloudDB"); + g_cacheDir = QString(cacheDir.absolutePath()+"/GoldenCheetahCloudDB/" + QString(QT_STRINGIFY(GC_CLOUD_DB_APP_NAME))); QDir newCacheDir(g_cacheDir); if (!newCacheDir.exists()) { - cacheDir.mkdir("GoldenCheetahCloudDB"); + newCacheDir.mkpath(g_cacheDir); } // general handling for sslErrors