Fix 3b50dd8 for reentrancy

Changed static variable for a member one,
the problem was apparent when opening a
different athlete besides the initial one.
This commit is contained in:
Alejandro Martinez
2024-04-12 12:10:50 -03:00
parent 3b50dd81a9
commit 3395c7a4c9
2 changed files with 6 additions and 3 deletions

View File

@@ -82,6 +82,9 @@ struct RideDBContext {
// is cache/rideDB.json an older version ?
bool old;
int loading;
// tracks the last progress update sent
double lastProgressUpdate;
};
#endif

View File

@@ -82,11 +82,10 @@ ride: '{' rideelement_list '}' {
jc->api->writeRideLine(jc->item, jc->request, jc->response);
#endif
} else {
static double last = 0.0;
double progress= round(double(jc->loading++) / double(jc->cache->rides().count()) * 100.0f);
if (progress > last) {
if (progress > jc->lastProgressUpdate) {
jc->context->notifyLoadProgress(jc->folder,progress);
last = progress;
jc->lastProgressUpdate = progress;
}
// find entry and update it
@@ -344,6 +343,7 @@ RideCache::load()
jc->api = NULL;
jc->old = false;
jc->loading = 0;
jc->lastProgressUpdate = 0.0;
jc->folder = context->athlete->home->root().canonicalPath();
// clean item