[filescanner] Make sure to split in transactions even when playlist tracks are unknown

This commit is contained in:
ejurgensen 2017-10-15 23:34:32 +02:00
parent 2d54d0d8fe
commit e9e8567e8c
2 changed files with 29 additions and 23 deletions

View File

@ -541,6 +541,7 @@ process_tracks(plist_t tracks)
uint64_t trk_id;
uint8_t disabled;
int ntracks;
int nloaded;
int mfi_id;
int ret;
@ -553,6 +554,7 @@ process_tracks(plist_t tracks)
db_transaction_begin();
ntracks = 0;
nloaded = 0;
iter = NULL;
plist_dict_new_iter(tracks, &iter);
@ -616,12 +618,6 @@ process_tracks(plist_t tracks)
free(str);
if (mfi_id <= 0)
{
plist_dict_next_item(tracks, iter, NULL, &trk);
continue;
}
ntracks++;
if (ntracks % 200 == 0)
{
@ -630,10 +626,18 @@ process_tracks(plist_t tracks)
db_transaction_begin();
}
if (mfi_id <= 0)
{
plist_dict_next_item(tracks, iter, NULL, &trk);
continue;
}
ret = id_map_add(trk_id, mfi_id);
if (ret < 0)
DPRINTF(E_LOG, L_SCAN, "Out of memory for itml -> db mapping\n");
nloaded++;
plist_dict_next_item(tracks, iter, NULL, &trk);
}
@ -641,7 +645,7 @@ process_tracks(plist_t tracks)
db_transaction_end();
return ntracks;
return nloaded;
}
@ -682,6 +686,10 @@ process_pl_items(plist_t items, int pl_id, const char *name)
continue;
}
ret = db_pl_add_item_byid(pl_id, db_id);
if (ret < 0)
DPRINTF(E_WARN, L_SCAN, "Could not add ID %d to playlist\n", db_id);
ntracks++;
if (ntracks % 200 == 0)
{
@ -689,10 +697,6 @@ process_pl_items(plist_t items, int pl_id, const char *name)
db_transaction_end();
db_transaction_begin();
}
ret = db_pl_add_item_byid(pl_id, db_id);
if (ret < 0)
DPRINTF(E_WARN, L_SCAN, "Could not add ID %d to playlist\n", db_id);
}
db_transaction_end();

View File

@ -207,7 +207,8 @@ scan_playlist(const char *file, time_t mtime, int dir_id)
int extinf;
int pl_id;
int pl_format;
int counter;
int ntracks;
int nadded;
int ret;
ptr = strrchr(file, '.');
@ -293,7 +294,8 @@ scan_playlist(const char *file, time_t mtime, int dir_id)
extinf = 0;
memset(&mfi, 0, sizeof(struct media_file_info));
counter = 0;
ntracks = 0;
nadded = 0;
while (fgets(buf, sizeof(buf), fp) != NULL)
{
@ -332,17 +334,17 @@ scan_playlist(const char *file, time_t mtime, int dir_id)
else
ret = process_regular_file(pl_id, path);
if (ret == 0)
ntracks++;
if (ntracks % 200 == 0)
{
counter++;
if (counter % 200 == 0)
{
DPRINTF(E_LOG, L_SCAN, "Processed %d items...\n", counter);
db_transaction_end();
db_transaction_begin();
}
DPRINTF(E_LOG, L_SCAN, "Processed %d items...\n", ntracks);
db_transaction_end();
db_transaction_begin();
}
if (ret == 0)
nadded++;
/* Clean up in preparation for next item */
extinf = 0;
free_mfi(&mfi, 1);
@ -355,9 +357,9 @@ scan_playlist(const char *file, time_t mtime, int dir_id)
free_mfi(&mfi, 1);
if (!feof(fp))
DPRINTF(E_LOG, L_SCAN, "Error reading playlist '%s' (only added %d tracks): %s\n", file, counter, strerror(errno));
DPRINTF(E_LOG, L_SCAN, "Error reading playlist '%s' (only added %d tracks): %s\n", file, nadded, strerror(errno));
else
DPRINTF(E_LOG, L_SCAN, "Done processing playlist, added/modified %d items\n", counter);
DPRINTF(E_LOG, L_SCAN, "Done processing playlist, added/modified %d items\n", nadded);
fclose(fp);
}