ImportWatcher -> BackgroundTask -> _processImportables
Continuing the push to remove explicit events for db changes
This commit is contained in:
parent
6f103b92bc
commit
937713de53
@ -27,6 +27,7 @@ export const removed = new Event('Image.removed');
|
||||
|
||||
// Watchers
|
||||
export const watcher = Watcher(db, SELECTOR);
|
||||
export const importWatcher = Watcher(db, IMPORT_SELECTOR);
|
||||
|
||||
// Methods
|
||||
const getId = id => (id.startsWith(PREFIX) ? id : `${PREFIX}_${id}`);
|
||||
@ -61,9 +62,6 @@ export async function add(imageFileList) {
|
||||
}
|
||||
}));
|
||||
const results = await db.bulkDocs(docs);
|
||||
|
||||
processImportables();
|
||||
|
||||
return docs.filter((d, i) => results[i].ok);
|
||||
}
|
||||
|
||||
@ -90,9 +88,14 @@ export async function addAttachment(doc, key, blob) {
|
||||
}
|
||||
|
||||
// Internal Functions
|
||||
const processImportables = backgroundTask(async function _processImportables() {
|
||||
importWatcher(
|
||||
backgroundTask(async function _processImportables(changeId, deleted) {
|
||||
if (deleted) {
|
||||
return;
|
||||
}
|
||||
const selector = changeId ? { _id: changeId } : IMPORT_SELECTOR;
|
||||
const result = await db.find({
|
||||
selector: IMPORT_SELECTOR,
|
||||
selector,
|
||||
limit: 1
|
||||
});
|
||||
|
||||
@ -162,5 +165,5 @@ const processImportables = backgroundTask(async function _processImportables() {
|
||||
}
|
||||
|
||||
await db.remove({ _id, _rev });
|
||||
processImportables();
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user