mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-13 12:42:20 +00:00
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]
This commit is contained in:
@@ -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<CommonAPIHeaderV1>* 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) {
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
bool curateChartByID(qint64 id, bool newStatus);
|
||||
void incrementDownloadCounterByID(qint64 id);
|
||||
bool getAllChartHeader(QList<CommonAPIHeaderV1>* 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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user