In song sync batch to db avoiding OOM

This commit is contained in:
Andrew Barnes 2015-01-31 21:57:00 +11:00
parent 70d58d8ace
commit 32e032af28
1 changed files with 10 additions and 12 deletions

View File

@ -1168,7 +1168,16 @@ public class LibrarySyncService extends Service {
action.execute(hostConnection, new ApiCallback<List<AudioType.DetailsSong>>() {
@Override
public void onSucess(List<AudioType.DetailsSong> result) {
allResults.addAll(result);
ContentValues songValuesBatch[] = new ContentValues[result.size()];
for (int i = 0; i < result.size(); i++) {
AudioType.DetailsSong song = result.get(i);
songValuesBatch[i] = SyncUtils.contentValuesFromSong(hostId, song);
}
// Insert the songs
contentResolver.bulkInsert(MediaContract.Songs.CONTENT_URI, songValuesBatch);
if (result.size() == LIMIT_SYNC_SONGS) {
// Max limit returned, there may be some more
LogUtils.LOGD(TAG, "chainCallSyncSongs: More results on media center, recursing.");
@ -1177,17 +1186,6 @@ public class LibrarySyncService extends Service {
} else {
// Ok, we have all the songs, insert them
LogUtils.LOGD(TAG, "chainCallSyncSongs: Got all results, continuing");
ContentValues songValuesBatch[] = new ContentValues[allResults.size()];
for (int i = 0; i < allResults.size(); i++) {
AudioType.DetailsSong song = allResults.get(i);
songValuesBatch[i] = SyncUtils.contentValuesFromSong(hostId, song);
}
// Insert the songs
contentResolver.bulkInsert(MediaContract.Songs.CONTENT_URI, songValuesBatch);
orchestrator.syncItemFinished();
}
}