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
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java
@@ -64,18 +64,21 @@ public class TelemetryUploadService exte
final TelemetryPingStore store = intent.getParcelableExtra(EXTRA_STORE);
uploadPendingPingsFromStore(this, store);
store.maybePrunePings();
Log.d(LOGTAG, "Service finished: upload and prune attempts completed");
}
private static void uploadPendingPingsFromStore(final Context context, final TelemetryPingStore store) {
final ArrayList<TelemetryPingFromStore> pingsToUpload = store.getAllPings();
+ 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) {
// There are minimal gains in trying to upload if we already failed one attempt.
if (delegate.hadConnectionError()) {
break;
}
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/stores/TelemetryJSONFilePingStore.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/stores/TelemetryJSONFilePingStore.java
@@ -181,16 +181,20 @@ public class TelemetryJSONFilePingStore
continue;
}
}
return out;
}
@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();
}
}
/**
* Locks the given {@link FileOutputStream} and writes the given String. This method will close the given stream.