GenerateThumbnails was loading too often
This commit is contained in:
parent
77b6bc929d
commit
6b0cfc0d2e
@ -1,7 +1,6 @@
|
||||
// import { createView } from 'domvm/dist/dev/domvm.dev.js';
|
||||
import { createView } from 'domvm/dist/full/domvm.full.js';
|
||||
|
||||
import * as image from './data/image.js';
|
||||
import generateThumbnails from './contextLoaders/generateThumbnails.js';
|
||||
import { GalleryView } from './interface/gallery.js';
|
||||
import { router } from './services/router.js';
|
||||
@ -12,9 +11,6 @@ import { EventEmitter } from 'events';
|
||||
EventEmitter.defaultMaxListeners = 1000; // https://github.com/pouchdb/pouchdb/issues/6123
|
||||
window.db = getDatabase();
|
||||
|
||||
// Watch for new images, generate thumbnails if they need them.
|
||||
image.watcher(generateThumbnails);
|
||||
|
||||
// Attach our root view to the DOM
|
||||
createView(GalleryView, {}).mount(document.querySelector('#app'));
|
||||
|
||||
|
||||
@ -1,6 +1,11 @@
|
||||
export default async function(id, deleted) {
|
||||
if (!deleted) {
|
||||
import * as image from '../data/image.js';
|
||||
|
||||
// Watch for new images, generate thumbnails if they need them.
|
||||
image.watcher(async function generateThumbnails(id, deleted, doc) {
|
||||
if (deleted || (doc.attachmentUrls.thumbnail && doc._attachments.thumbnail)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const module = await import('../context/generateThumbnails');
|
||||
module.invoke(id, deleted);
|
||||
}
|
||||
}
|
||||
module.invoke(id);
|
||||
});
|
||||
|
||||
@ -26,7 +26,7 @@ export const imported = new Event('Image.imported');
|
||||
export const removed = new Event('Image.removed');
|
||||
|
||||
// Watchers
|
||||
export const watcher = Watcher(db, SELECTOR);
|
||||
export const watcher = Watcher(db, SELECTOR, true);
|
||||
export const importWatcher = Watcher(db, IMPORT_SELECTOR);
|
||||
|
||||
// Methods
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { log, error } from '../services/console.js';
|
||||
|
||||
export function Watcher(db, selector) {
|
||||
export function Watcher(db, selector, include_docs) {
|
||||
const subscribers = new Set();
|
||||
let changes = null;
|
||||
|
||||
@ -13,11 +13,13 @@ export function Watcher(db, selector) {
|
||||
.changes({
|
||||
since: 'now',
|
||||
live: true,
|
||||
include_docs,
|
||||
selector
|
||||
})
|
||||
.on('change', change => {
|
||||
log('changed:', change);
|
||||
subscribers.forEach(s => s(change.id, !!change.deleted));
|
||||
const { id, deleted, doc } = change;
|
||||
subscribers.forEach(s => s(id, !!deleted, doc));
|
||||
})
|
||||
.on('error', err => {
|
||||
error(err);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user