From 719545fd3d54ed445d217e77b9a5005c6ba27c4f Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Wed, 2 May 2018 21:49:36 +0200 Subject: [PATCH] Prevent thrashing the database by opening and closing rapidly Reduces number of real close() calls to the database from multiple times per second to one single time --- .../antennapod/core/service/download/DownloadService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java index a62c9d8bf..57c1964f1 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java @@ -22,6 +22,7 @@ import android.util.Log; import android.util.Pair; import android.webkit.URLUtil; +import de.danoeh.antennapod.core.storage.PodDBAdapter; import org.apache.commons.io.FileUtils; import org.xml.sax.SAXException; @@ -258,6 +259,7 @@ public class DownloadService extends Service { public void onCreate() { Log.d(TAG, "Service started"); isRunning = true; + PodDBAdapter.getInstance().open(); // Prevent thrashing the database by opening and closing rapidly handler = new Handler(); reportQueue = Collections.synchronizedList(new ArrayList<>()); downloads = Collections.synchronizedList(new ArrayList<>()); @@ -336,6 +338,7 @@ public class DownloadService extends Service { // start auto download in case anything new has shown up DBTasks.autodownloadUndownloadedItems(getApplicationContext()); + PodDBAdapter.getInstance().close(); } private void setupNotificationBuilders() {