implement clear cache option after context change

This commit is contained in:
Yannik Schmidt
2020-09-07 16:00:58 +02:00
parent 3f6862e26b
commit e21b1ac3ca
5 changed files with 38 additions and 0 deletions

View File

@@ -99,6 +99,16 @@ void ServerConfig::addNewPP(){
}
}
void ServerConfig::askFlushServerCache(){
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "Server Cache",
"Sollen alte Transcripte auf dem Server, die ohne diese Konfiguration erstellt wurden gelöscht werden?",
QMessageBox::Yes|QMessageBox::No);
if (reply == QMessageBox::Yes) {
sc->flushCache();
}
}
void ServerConfig::addNewContext()
{
QStringList *sl = new QStringList();
@@ -112,6 +122,7 @@ void ServerConfig::addNewContext()
auto lineEdit = static_cast<QLineEdit*>(wl->at(0));
if(!lineEdit->text().isEmpty()){
sc->submitSpeechContextPhraseChange(lineEdit->text());
askFlushServerCache();
}
}
}
@@ -137,10 +148,26 @@ void ServerConfig::finishedRequest(QNetworkReply *reply){
QString addPP = sc->buildURLFromLocation(PP_EDIT);
QString addContext = sc->buildURLFromLocation(CONTEXT_EDIT);
QString flushCache = sc->buildURLFromLocation(FLUSH_SERVER_CACHE);
if(QString::compare(reply->url().toString(), addPP) == 0){
sc->getUnifiedServerConfig();
}else if(QString::compare(reply->url().toString(), addContext) == 0){
sc->getUnifiedServerConfig();
}else if(QString::compare(reply->url().toString(), flushCache) == 0){
qDebug("WTF");
QMessageBox msgBox;
msgBox.setText("Server Cache Gelöscht");
QJsonObject jsonFlushCache = QJsonDocument::fromJson(reply->readAll()).object();
QJsonArray removals = jsonFlushCache["removals"].toArray();
QString display = "";
for(int i = 0; i < removals.size(); i++){
display += removals[i].toString();
display += "<br>";
}
msgBox.setInformativeText(display);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
}else{
/* this is the unified server config query */
/* get filename and tracking id from replay */

View File

@@ -30,6 +30,7 @@ private:
QTableWidget* ppTable;
QTableWidget* contextTable;
ServerConnection* sc;
void askFlushServerCache();
};
#endif // SERVERCONFIG_H

View File

@@ -149,3 +149,10 @@ void ServerConnection::getUnifiedServerConfig(){
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
networkManager->get(request);
}
void ServerConnection::flushCache(){
QUrl serviceUrl = QUrl(buildURLFromLocation(QString(FLUSH_SERVER_CACHE)));
QNetworkRequest request(serviceUrl);
request.setRawHeader(AUTH_HEADER_NAME, authHeaderData);
networkManager->get(request);
}

View File

@@ -22,6 +22,7 @@ public:
void getSpeechContextPhrases();
void getUnifiedServerConfig();
QString buildURLFromLocation(const char *location);
void flushCache();
public slots:
void queryStatusAll();
private slots:

2
urls.h
View File

@@ -10,4 +10,6 @@
#define UNIFIED_GET "/unified-server-settings"
#define SERVER_INFO "/server-info"
#define FLUSH_SERVER_CACHE "/flush-cache"
#endif // URLS_H