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