mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-29 00:23:23 -05:00
[filescanner] Make sure to split in transactions even when playlist tracks are unknown
This commit is contained in:
parent
2d54d0d8fe
commit
e9e8567e8c
@ -541,6 +541,7 @@ process_tracks(plist_t tracks)
|
|||||||
uint64_t trk_id;
|
uint64_t trk_id;
|
||||||
uint8_t disabled;
|
uint8_t disabled;
|
||||||
int ntracks;
|
int ntracks;
|
||||||
|
int nloaded;
|
||||||
int mfi_id;
|
int mfi_id;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -553,6 +554,7 @@ process_tracks(plist_t tracks)
|
|||||||
db_transaction_begin();
|
db_transaction_begin();
|
||||||
|
|
||||||
ntracks = 0;
|
ntracks = 0;
|
||||||
|
nloaded = 0;
|
||||||
|
|
||||||
iter = NULL;
|
iter = NULL;
|
||||||
plist_dict_new_iter(tracks, &iter);
|
plist_dict_new_iter(tracks, &iter);
|
||||||
@ -616,12 +618,6 @@ process_tracks(plist_t tracks)
|
|||||||
|
|
||||||
free(str);
|
free(str);
|
||||||
|
|
||||||
if (mfi_id <= 0)
|
|
||||||
{
|
|
||||||
plist_dict_next_item(tracks, iter, NULL, &trk);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ntracks++;
|
ntracks++;
|
||||||
if (ntracks % 200 == 0)
|
if (ntracks % 200 == 0)
|
||||||
{
|
{
|
||||||
@ -630,10 +626,18 @@ process_tracks(plist_t tracks)
|
|||||||
db_transaction_begin();
|
db_transaction_begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mfi_id <= 0)
|
||||||
|
{
|
||||||
|
plist_dict_next_item(tracks, iter, NULL, &trk);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ret = id_map_add(trk_id, mfi_id);
|
ret = id_map_add(trk_id, mfi_id);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
DPRINTF(E_LOG, L_SCAN, "Out of memory for itml -> db mapping\n");
|
DPRINTF(E_LOG, L_SCAN, "Out of memory for itml -> db mapping\n");
|
||||||
|
|
||||||
|
nloaded++;
|
||||||
|
|
||||||
plist_dict_next_item(tracks, iter, NULL, &trk);
|
plist_dict_next_item(tracks, iter, NULL, &trk);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -641,7 +645,7 @@ process_tracks(plist_t tracks)
|
|||||||
|
|
||||||
db_transaction_end();
|
db_transaction_end();
|
||||||
|
|
||||||
return ntracks;
|
return nloaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -682,6 +686,10 @@ process_pl_items(plist_t items, int pl_id, const char *name)
|
|||||||
continue;
|
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++;
|
ntracks++;
|
||||||
if (ntracks % 200 == 0)
|
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_end();
|
||||||
db_transaction_begin();
|
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();
|
db_transaction_end();
|
||||||
|
@ -207,7 +207,8 @@ scan_playlist(const char *file, time_t mtime, int dir_id)
|
|||||||
int extinf;
|
int extinf;
|
||||||
int pl_id;
|
int pl_id;
|
||||||
int pl_format;
|
int pl_format;
|
||||||
int counter;
|
int ntracks;
|
||||||
|
int nadded;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ptr = strrchr(file, '.');
|
ptr = strrchr(file, '.');
|
||||||
@ -293,7 +294,8 @@ scan_playlist(const char *file, time_t mtime, int dir_id)
|
|||||||
|
|
||||||
extinf = 0;
|
extinf = 0;
|
||||||
memset(&mfi, 0, sizeof(struct media_file_info));
|
memset(&mfi, 0, sizeof(struct media_file_info));
|
||||||
counter = 0;
|
ntracks = 0;
|
||||||
|
nadded = 0;
|
||||||
|
|
||||||
while (fgets(buf, sizeof(buf), fp) != NULL)
|
while (fgets(buf, sizeof(buf), fp) != NULL)
|
||||||
{
|
{
|
||||||
@ -332,17 +334,17 @@ scan_playlist(const char *file, time_t mtime, int dir_id)
|
|||||||
else
|
else
|
||||||
ret = process_regular_file(pl_id, path);
|
ret = process_regular_file(pl_id, path);
|
||||||
|
|
||||||
if (ret == 0)
|
ntracks++;
|
||||||
|
if (ntracks % 200 == 0)
|
||||||
{
|
{
|
||||||
counter++;
|
DPRINTF(E_LOG, L_SCAN, "Processed %d items...\n", ntracks);
|
||||||
if (counter % 200 == 0)
|
db_transaction_end();
|
||||||
{
|
db_transaction_begin();
|
||||||
DPRINTF(E_LOG, L_SCAN, "Processed %d items...\n", counter);
|
|
||||||
db_transaction_end();
|
|
||||||
db_transaction_begin();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ret == 0)
|
||||||
|
nadded++;
|
||||||
|
|
||||||
/* Clean up in preparation for next item */
|
/* Clean up in preparation for next item */
|
||||||
extinf = 0;
|
extinf = 0;
|
||||||
free_mfi(&mfi, 1);
|
free_mfi(&mfi, 1);
|
||||||
@ -355,9 +357,9 @@ scan_playlist(const char *file, time_t mtime, int dir_id)
|
|||||||
free_mfi(&mfi, 1);
|
free_mfi(&mfi, 1);
|
||||||
|
|
||||||
if (!feof(fp))
|
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
|
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);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user