@@ -925,6 +925,7 @@ DownloadManager::UploadScore(HighScore* hs,
925
925
LOG->Trace (
926
926
" Attempted to upload score when not logged in (scorekey: \" %s\" )" ,
927
927
hs->GetScoreKey ().c_str ());
928
+ callback ();
928
929
return ;
929
930
}
930
931
@@ -979,8 +980,8 @@ DownloadManager::UploadScore(HighScore* hs,
979
980
curlHandle, form, lastPtr, " replay_data" , replayString);
980
981
SetCURLPostToURL (curlHandle, url);
981
982
curl_easy_setopt (curlHandle, CURLOPT_HTTPPOST, form);
982
- auto done = [this , hs, callback{ move (callback) } , load_from_disk](
983
- HTTPRequest& req, CURLMsg*) {
983
+ auto done = [this , hs, callback, load_from_disk](HTTPRequest& req,
984
+ CURLMsg*) {
984
985
long response_code;
985
986
curl_easy_getinfo (req.handle , CURLINFO_RESPONSE_CODE, &response_code);
986
987
Document d;
@@ -1008,8 +1009,7 @@ DownloadManager::UploadScore(HighScore* hs,
1008
1009
DLMAN->StartSession (
1009
1010
DLMAN->sessionUser ,
1010
1011
DLMAN->sessionPass ,
1011
- [hs, callback{ move (callback) }, load_from_disk](
1012
- bool logged) {
1012
+ [hs, callback, load_from_disk](bool logged) {
1013
1013
if (logged) {
1014
1014
DLMAN->UploadScore (hs, callback, load_from_disk);
1015
1015
}
@@ -1084,8 +1084,10 @@ DownloadManager::UploadScore(HighScore* hs,
1084
1084
}
1085
1085
callback ();
1086
1086
};
1087
- // TODO: Do we want to call callback in the fail HTTPRequest handler?
1088
- HTTPRequest* req = new HTTPRequest (curlHandle, done);
1087
+ HTTPRequest* req = new HTTPRequest (
1088
+ curlHandle, done, nullptr , [callback](HTTPRequest& req, CURLMsg*) {
1089
+ callback ();
1090
+ });
1089
1091
SetCURLResultsString (curlHandle, &(req->result ));
1090
1092
curl_multi_add_handle (mHTTPHandle , req->handle );
1091
1093
HTTPRequests.push_back (req);
@@ -1119,21 +1121,19 @@ DownloadManager::UploadScoreWithReplayDataFromDisk(HighScore* hs,
1119
1121
// (So it is essentially kind of recursive, with the base case of an empty
1120
1122
// deque)
1121
1123
void
1122
- uploadSequentially (deque<HighScore*> toUpload, int workload )
1124
+ uploadSequentially ()
1123
1125
{
1124
1126
Message msg (" UploadProgress" );
1125
- msg.SetParam (" percent" ,
1126
- 1 .f - (static_cast <float >(toUpload.size ()) /
1127
- static_cast <float >(workload)));
1127
+ msg.SetParam (
1128
+ " percent" ,
1129
+ 1 .f - (static_cast <float >(DLMAN->ScoreUploadSequentialQueue .size ()) /
1130
+ static_cast <float >(DLMAN->sequentialScoreUploadTotalWorkload )));
1128
1131
MESSAGEMAN->Broadcast (msg);
1129
1132
1130
- if (!toUpload.empty ()) {
1131
- auto hs = toUpload.front ();
1132
- toUpload.pop_front ();
1133
- DLMAN->UploadScoreWithReplayDataFromDisk (
1134
- hs, [hs, toUpload{ move (toUpload) }, workload]() {
1135
- uploadSequentially (toUpload, workload);
1136
- });
1133
+ if (!DLMAN->ScoreUploadSequentialQueue .empty ()) {
1134
+ auto hs = DLMAN->ScoreUploadSequentialQueue .front ();
1135
+ DLMAN->ScoreUploadSequentialQueue .pop_front ();
1136
+ DLMAN->UploadScoreWithReplayDataFromDisk (hs, uploadSequentially);
1137
1137
}
1138
1138
return ;
1139
1139
}
@@ -1144,10 +1144,10 @@ DownloadManager::UploadScores()
1144
1144
if (!LoggedIn ())
1145
1145
return false ;
1146
1146
1147
- // First we accumulate top 2 scores that have not been uploaded and have
1148
- // replay data
1147
+ // First we accumulate top 2 scores that have
1148
+ // not been uploaded and have replay data
1149
1149
auto scores = SCOREMAN->GetAllPBPtrs ();
1150
- deque <HighScore*> toUpload;
1150
+ vector <HighScore*> toUpload;
1151
1151
for (auto & vec : scores) {
1152
1152
for (auto & scorePtr : vec) {
1153
1153
auto ts = scorePtr->GetTopScore ();
@@ -1172,74 +1172,81 @@ DownloadManager::UploadScores()
1172
1172
if (!toUpload.empty ())
1173
1173
LOG->Trace (" Updating online scores. (Uploading %d scores)" ,
1174
1174
toUpload.size ());
1175
- uploadSequentially (toUpload, toUpload.size ());
1175
+
1176
+ bool was_not_uploading_already = this ->ScoreUploadSequentialQueue .empty ();
1177
+ if (was_not_uploading_already)
1178
+ this ->sequentialScoreUploadTotalWorkload = toUpload.size ();
1179
+ else
1180
+ this ->sequentialScoreUploadTotalWorkload += toUpload.size ();
1181
+ this ->ScoreUploadSequentialQueue .insert (
1182
+ this ->ScoreUploadSequentialQueue .end (), toUpload.begin (), toUpload.end ());
1183
+ if (was_not_uploading_already)
1184
+ uploadSequentially ();
1176
1185
1177
1186
return true ;
1178
1187
}
1179
- void
1180
- DownloadManager::BeginSequentialUploadOfAccumulatedQueue ()
1181
- {
1182
- // figure out how to make this not start if there are active uploads
1183
- uploadSequentially (ForceUploadScoreQueue, ForceUploadScoreQueue.size ());
1184
- ForceUploadScoreQueue.clear ();
1185
- ForceUploadScoreQueue.shrink_to_fit ();
1186
- }
1187
1188
1188
1189
// manual upload function that will upload all scores for a chart
1189
1190
// that skips some of the constraints of the auto uploaders
1190
1191
void
1191
1192
DownloadManager::ForceUploadScoresForChart (const std::string& ck, bool startnow)
1192
1193
{
1193
- // This check is a bit redundant, we don't want to try to begin the upload
1194
- // when this is called from within a "bigger" forceupload, either of these
1195
- // checks should be enough I think
1196
- startnow = startnow && ForceUploadScoreQueue.empty ();
1194
+ startnow = startnow && this ->ScoreUploadSequentialQueue .empty ();
1197
1195
auto cs = SCOREMAN->GetScoresForChart (ck);
1198
1196
if (cs) { // ignoring topscore flags; upload worst->best
1199
1197
auto & test = cs->GetAllScores ();
1200
1198
for (auto & s : test)
1201
1199
if (!s->forceuploadedthissession )
1202
- if (s->GetGrade () != Grade_Failed)
1203
- ForceUploadScoreQueue.push_back (s);
1200
+ if (s->GetGrade () != Grade_Failed) {
1201
+ this ->ScoreUploadSequentialQueue .push_back (s);
1202
+ this ->sequentialScoreUploadTotalWorkload += 1 ;
1203
+ }
1204
1204
}
1205
1205
1206
1206
if (startnow) {
1207
+ this ->sequentialScoreUploadTotalWorkload =
1208
+ this ->ScoreUploadSequentialQueue .size ();
1207
1209
LOG->Trace (" Starting sequential upload of %d scores" ,
1208
- ForceUploadScoreQueue .size ());
1209
- BeginSequentialUploadOfAccumulatedQueue ();
1210
+ this -> ScoreUploadSequentialQueue .size ());
1211
+ uploadSequentially ();
1210
1212
}
1211
1213
}
1212
1214
// wrapper for packs
1213
1215
void
1214
1216
DownloadManager::ForceUploadScoresForPack (const std::string& pack,
1215
1217
bool startnow)
1216
1218
{
1217
- // This check is a bit redundant, we don't want to try to begin the
1218
- // upload when this is called from within a "bigger" forceupload, either
1219
- // of these checks should be enough I think
1220
- startnow = startnow && ForceUploadScoreQueue.empty ();
1219
+ startnow = startnow && this ->ScoreUploadSequentialQueue .empty ();
1221
1220
auto songs = SONGMAN->GetSongs (pack);
1222
1221
for (auto so : songs)
1223
1222
for (auto c : so->GetAllSteps ())
1224
1223
ForceUploadScoresForChart (c->GetChartKey (), false );
1225
1224
1226
1225
if (startnow) {
1226
+ this ->sequentialScoreUploadTotalWorkload =
1227
+ this ->ScoreUploadSequentialQueue .size ();
1227
1228
LOG->Trace (" Starting sequential upload of %d scores" ,
1228
- ForceUploadScoreQueue .size ());
1229
- BeginSequentialUploadOfAccumulatedQueue ();
1229
+ this -> ScoreUploadSequentialQueue .size ());
1230
+ uploadSequentially ();
1230
1231
}
1231
1232
}
1232
1233
void
1233
1234
DownloadManager::ForceUploadAllScores ()
1234
1235
{
1236
+ bool not_already_uploading = this ->ScoreUploadSequentialQueue .empty ();
1237
+
1235
1238
auto songs = SONGMAN->GetSongs (GROUP_ALL);
1236
1239
for (auto so : songs)
1237
1240
for (auto c : so->GetAllSteps ())
1238
1241
ForceUploadScoresForChart (c->GetChartKey (), false );
1239
1242
1240
- LOG->Trace (" Starting sequential upload of %d scores" ,
1241
- ForceUploadScoreQueue.size ());
1242
- BeginSequentialUploadOfAccumulatedQueue ();
1243
+ if (not_already_uploading) {
1244
+ this ->sequentialScoreUploadTotalWorkload =
1245
+ this ->ScoreUploadSequentialQueue .size ();
1246
+ LOG->Trace (" Starting sequential upload of %d scores" ,
1247
+ this ->ScoreUploadSequentialQueue .size ());
1248
+ uploadSequentially ();
1249
+ }
1243
1250
}
1244
1251
void
1245
1252
DownloadManager::EndSessionIfExists ()
0 commit comments