From fb5dd484ed3db19c55d66b03c567c767420ad132 Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Fri, 29 Apr 2016 15:21:10 -0700 Subject: [PATCH] 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 --- .../org/mozilla/gecko/telemetry/TelemetryUploadService.java | 5 ++++- .../gecko/telemetry/stores/TelemetryJSONFilePingStore.java | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java index ecb130774bfe..06fee7f9f010 100644 --- a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java +++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java @@ -69,8 +69,11 @@ public class TelemetryUploadService extends IntentService { private static void uploadPendingPingsFromStore(final Context context, final TelemetryPingStore store) { final ArrayList pingsToUpload = store.getAllPings(); - final String serverSchemeHostPort = getServerSchemeHostPort(context); + if (pingsToUpload.isEmpty()) { + return true; + } + final String serverSchemeHostPort = getServerSchemeHostPort(context); final HashSet successfulUploadIDs = new HashSet<>(pingsToUpload.size()); // used for side effects. final PingResultDelegate delegate = new PingResultDelegate(successfulUploadIDs); for (final TelemetryPingFromStore ping : pingsToUpload) { diff --git a/mobile/android/base/java/org/mozilla/gecko/telemetry/stores/TelemetryJSONFilePingStore.java b/mobile/android/base/java/org/mozilla/gecko/telemetry/stores/TelemetryJSONFilePingStore.java index e2c97178b6e9..066a1bc94eda 100644 --- a/mobile/android/base/java/org/mozilla/gecko/telemetry/stores/TelemetryJSONFilePingStore.java +++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/stores/TelemetryJSONFilePingStore.java @@ -186,6 +186,10 @@ public class TelemetryJSONFilePingStore implements TelemetryPingStore { @Override public void onUploadAttemptComplete(final Set successfulRemoveIDs) { + if (successfulRemoveIDs.isEmpty()) { + return; + } + final File[] files = storeDir.listFiles(new PingFileFilter(successfulRemoveIDs)); for (final File file : files) { file.delete();