Bug 1243585 - Add short-circuits when there are no pings. r=sebastian

Ideally, we'd just not run the service but skimming, I see no clean way to do
that with the existing code.

MozReview-Commit-ID: HRU1PAmYoil

--HG--
extra : rebase_source : 63074ae8dcd2613ff90d3f431fe2e58f51364e03
This commit is contained in:
Michael Comella 2016-04-29 15:21:10 -07:00
parent e90e46946b
commit fb5dd484ed
2 changed files with 8 additions and 1 deletions

View File

@ -69,8 +69,11 @@ public class TelemetryUploadService extends IntentService {
private static void uploadPendingPingsFromStore(final Context context, final TelemetryPingStore store) {
final ArrayList<TelemetryPingFromStore> pingsToUpload = store.getAllPings();
final String serverSchemeHostPort = getServerSchemeHostPort(context);
if (pingsToUpload.isEmpty()) {
return true;
}
final String serverSchemeHostPort = getServerSchemeHostPort(context);
final HashSet<Integer> successfulUploadIDs = new HashSet<>(pingsToUpload.size()); // used for side effects.
final PingResultDelegate delegate = new PingResultDelegate(successfulUploadIDs);
for (final TelemetryPingFromStore ping : pingsToUpload) {

View File

@ -186,6 +186,10 @@ public class TelemetryJSONFilePingStore implements TelemetryPingStore {
@Override
public void onUploadAttemptComplete(final Set<Integer> successfulRemoveIDs) {
if (successfulRemoveIDs.isEmpty()) {
return;
}
final File[] files = storeDir.listFiles(new PingFileFilter(successfulRemoveIDs));
for (final File file : files) {
file.delete();