Add a flag to cdb/set-fields to avoid needing to pass all book ids for dirtied updates

This commit is contained in:
Kovid Goyal 2019-01-22 13:38:33 +05:30
parent eab43eb63e
commit 8fbdd7bc9a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -144,6 +144,7 @@ def cdb_set_fields(ctx, rd, book_id, library_id):
raise HTTPBadRequest('Invalid encoded data')
try:
changes, loaded_book_ids = data['changes'], frozenset(map(int, data.get('loaded_book_ids', ())))
all_dirtied = bool(data.get('all_dirtied'))
if not isinstance(changes, dict):
raise TypeError('changes must be a dict')
except Exception:
@ -168,4 +169,6 @@ def cdb_set_fields(ctx, rd, book_id, library_id):
for field, value in changes.iteritems():
dirtied |= db.set_field(field, {book_id: value})
ctx.notify_changes(db.backend.library_path, metadata(dirtied))
return {bid: book_as_json(db, book_id) for bid in (dirtied & loaded_book_ids) | {book_id}}
all_ids = dirtied if all_dirtied else (dirtied & loaded_book_ids)
all_ids |= {book_id}
return {bid: book_as_json(db, book_id) for bid in all_ids}