diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-08-19 14:30:22 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-08-19 14:30:22 -0700 |
commit | 394f80983202b053c39e14a6795c38908ec2590f (patch) | |
tree | 89cb5836b6f14aa5bdc6c869405a9c18045db7ca | |
parent | 8902e0cd95fac9cf8e7a18a80dc5c05a08095452 (diff) | |
download | dsub-394f80983202b053c39e14a6795c38908ec2590f.tar.gz dsub-394f80983202b053c39e14a6795c38908ec2590f.tar.bz2 dsub-394f80983202b053c39e14a6795c38908ec2590f.zip |
Add variable singleUpdate to cache serializers
In some cases we need to iterate over every single entry in a list in order to ensure all cases are covered. This is the minority though, and performance shouldn't be impeded for the other cases.
-rw-r--r-- | src/github/daneren2005/dsub/service/CachedMusicService.java | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java index 5fd332d6..d919775b 100644 --- a/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -581,7 +581,7 @@ public class CachedMusicService implements MusicService { } for (String parent : parents) { - new MusicDirectoryUpdater(context, cacheName, parent) { + new MusicDirectoryUpdater(context, cacheName, parent, checkIds.size() == 1) { @Override public boolean checkResult(Entry check) { for (String id : checkIds) { @@ -1036,14 +1036,23 @@ public class CachedMusicService implements MusicService { private abstract class SerializeUpdater<T> { final Context context; final String cacheName; + final boolean singleUpdate; public SerializeUpdater(Context context, String cacheName) { + this(context, cacheName, true); + } + public SerializeUpdater(Context context, String cacheName, boolean singleUpdate) { this.context = context; this.cacheName = getCacheName(context, cacheName); + this.singleUpdate = singleUpdate; } - public SerializeUpdater(Context context, String cacheName, String id) { + public SerializeUpdater(Context context, String cacheName, String id) { + this(context, cacheName, id, true); + } + public SerializeUpdater(Context context, String cacheName, String id, boolean singleUpdate) { this.context = context; this.cacheName = getCacheName(context, cacheName, id); + this.singleUpdate = singleUpdate; } public ArrayList<T> getArrayList() { @@ -1064,6 +1073,9 @@ public class CachedMusicService implements MusicService { for(T check: objects) { if(checkResult(check)) { objects.push(check); + if(singleUpdate) { + break; + } } } @@ -1109,7 +1121,10 @@ public class CachedMusicService implements MusicService { private MusicDirectory musicDirectory; public MusicDirectoryUpdater(Context context, String cacheName, String id) { - super(context, cacheName, id); + super(context, cacheName, id, true); + } + public MusicDirectoryUpdater(Context context, String cacheName, String id, boolean singleUpdate) { + super(context, cacheName, id, singleUpdate); } @Override @@ -1144,7 +1159,7 @@ public class CachedMusicService implements MusicService { } for(Playlist playlist: playlists) { - new MusicDirectoryUpdater(context, "playlist", playlist.getId()) { + new MusicDirectoryUpdater(context, "playlist", playlist.getId(), false) { @Override public boolean checkResult(Entry check) { return PlaylistDirectoryUpdater.this.checkResult(check); |