mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
fixing taskQue
This commit is contained in:
parent
bda5fef910
commit
a7be82a59a
@ -88,7 +88,6 @@ export class GalleryManager implements IGalleryManager, ISQLGalleryManager {
|
|||||||
|
|
||||||
|
|
||||||
const dir = await this.selectParentDir(connection, directoryName, directoryParent);
|
const dir = await this.selectParentDir(connection, directoryName, directoryParent);
|
||||||
|
|
||||||
if (dir && dir.lastScanned != null) {
|
if (dir && dir.lastScanned != null) {
|
||||||
// If it seems that the content did not changed, do not work on it
|
// If it seems that the content did not changed, do not work on it
|
||||||
if (knownLastModified && knownLastScanned
|
if (knownLastModified && knownLastScanned
|
||||||
@ -102,25 +101,25 @@ export class GalleryManager implements IGalleryManager, ISQLGalleryManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await this.fillParentDir(connection, dir);
|
|
||||||
|
|
||||||
|
|
||||||
if (dir.lastModified !== lastModified) {
|
if (dir.lastModified !== lastModified) {
|
||||||
return this.indexDirectory(relativeDirectoryName);
|
return this.indexDirectory(relativeDirectoryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// not indexed since a while, index it in a lazy manner
|
// not indexed since a while, index it in a lazy manner
|
||||||
if ((Date.now() - dir.lastScanned > Config.Server.indexing.cachedFolderTimeout &&
|
if ((Date.now() - dir.lastScanned > Config.Server.indexing.cachedFolderTimeout &&
|
||||||
Config.Server.indexing.reIndexingSensitivity >= ReIndexingSensitivity.medium) ||
|
Config.Server.indexing.reIndexingSensitivity >= ReIndexingSensitivity.medium) ||
|
||||||
Config.Server.indexing.reIndexingSensitivity >= ReIndexingSensitivity.high) {
|
Config.Server.indexing.reIndexingSensitivity >= ReIndexingSensitivity.high) {
|
||||||
// on the fly reindexing
|
// on the fly reindexing
|
||||||
|
|
||||||
this.indexDirectory(relativeDirectoryName).catch((err) => {
|
this.indexDirectory(relativeDirectoryName).catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
await this.fillParentDir(connection, dir);
|
||||||
return dir;
|
return dir;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// never scanned (deep indexed), do it and return with it
|
// never scanned (deep indexed), do it and return with it
|
||||||
@ -275,7 +274,7 @@ export class GalleryManager implements IGalleryManager, ISQLGalleryManager {
|
|||||||
delete directory.media;
|
delete directory.media;
|
||||||
await directoryRepository.save(directory);
|
await directoryRepository.save(directory);
|
||||||
}
|
}
|
||||||
} else { //dir does not exists yet
|
} else { // dir does not exists yet
|
||||||
scannedDirectory.directories[i].parent = currentDir;
|
scannedDirectory.directories[i].parent = currentDir;
|
||||||
(<DirectoryEntity>scannedDirectory.directories[i]).lastScanned = null; // new child dir, not fully scanned yet
|
(<DirectoryEntity>scannedDirectory.directories[i]).lastScanned = null; // new child dir, not fully scanned yet
|
||||||
const d = await directoryRepository.save(<DirectoryEntity>scannedDirectory.directories[i]);
|
const d = await directoryRepository.save(<DirectoryEntity>scannedDirectory.directories[i]);
|
||||||
@ -375,7 +374,7 @@ export class GalleryManager implements IGalleryManager, ISQLGalleryManager {
|
|||||||
|
|
||||||
async countMediaSize(): Promise<number> {
|
async countMediaSize(): Promise<number> {
|
||||||
const connection = await SQLConnection.getConnection();
|
const connection = await SQLConnection.getConnection();
|
||||||
let {sum} = await connection.getRepository(MediaEntity)
|
const {sum} = await connection.getRepository(MediaEntity)
|
||||||
.createQueryBuilder('media')
|
.createQueryBuilder('media')
|
||||||
.select('SUM(media.metadata.fileSize)', 'sum')
|
.select('SUM(media.metadata.fileSize)', 'sum')
|
||||||
.getRawOne();
|
.getRawOne();
|
||||||
|
@ -72,7 +72,6 @@ export class DiskMangerWorker {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (let i = 0; i < list.length; i++) {
|
for (let i = 0; i < list.length; i++) {
|
||||||
const file = list[i];
|
const file = list[i];
|
||||||
|
@ -67,8 +67,8 @@ export class MetadataLoader {
|
|||||||
|
|
||||||
const data = Buffer.allocUnsafe(Config.Server.photoMetadataSize);
|
const data = Buffer.allocUnsafe(Config.Server.photoMetadataSize);
|
||||||
fs.read(fd, data, 0, Config.Server.photoMetadataSize, 0, (err) => {
|
fs.read(fd, data, 0, Config.Server.photoMetadataSize, 0, (err) => {
|
||||||
|
fs.closeSync(fd);
|
||||||
if (err) {
|
if (err) {
|
||||||
fs.closeSync(fd);
|
|
||||||
return reject({file: fullPath, error: err});
|
return reject({file: fullPath, error: err});
|
||||||
}
|
}
|
||||||
const metadata: PhotoMetadata = {
|
const metadata: PhotoMetadata = {
|
||||||
@ -157,10 +157,8 @@ export class MetadataLoader {
|
|||||||
|
|
||||||
metadata.creationDate = metadata.creationDate || 0;
|
metadata.creationDate = metadata.creationDate || 0;
|
||||||
|
|
||||||
fs.closeSync(fd);
|
|
||||||
return resolve(metadata);
|
return resolve(metadata);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
fs.closeSync(fd);
|
|
||||||
return reject({file: fullPath, error: err});
|
return reject({file: fullPath, error: err});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -53,6 +53,10 @@ export class TaskQue<I, O> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ready(task: TaskQueEntry<I, O>): void {
|
public ready(task: TaskQueEntry<I, O>): void {
|
||||||
this.processing.slice(this.processing.indexOf(task), 1);
|
const index = this.processing.indexOf(task);
|
||||||
|
if (index === -1) {
|
||||||
|
throw new Error('Task does not exist');
|
||||||
|
}
|
||||||
|
this.processing.splice(index, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,6 +165,7 @@ export class ImageRendererFactory {
|
|||||||
|
|
||||||
public static Sharp() {
|
public static Sharp() {
|
||||||
const sharp = require('sharp');
|
const sharp = require('sharp');
|
||||||
|
sharp.cache(false);
|
||||||
return async (input: RendererInput): Promise<void> => {
|
return async (input: RendererInput): Promise<void> => {
|
||||||
|
|
||||||
Logger.silly('[SharpThRenderer] rendering thumbnail:' + input.mediaPath);
|
Logger.silly('[SharpThRenderer] rendering thumbnail:' + input.mediaPath);
|
||||||
|
@ -2,7 +2,7 @@ import {expect} from 'chai';
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import {Config} from '../../../../../common/config/private/Config';
|
import {Config} from '../../../../../common/config/private/Config';
|
||||||
import {DatabaseType} from '../../../../../common/config/private/IPrivateConfig';
|
import {DatabaseType, ReIndexingSensitivity} from '../../../../../common/config/private/IPrivateConfig';
|
||||||
import {SQLConnection} from '../../../../../backend/model/sql/SQLConnection';
|
import {SQLConnection} from '../../../../../backend/model/sql/SQLConnection';
|
||||||
import {GalleryManager} from '../../../../../backend/model/sql/GalleryManager';
|
import {GalleryManager} from '../../../../../backend/model/sql/GalleryManager';
|
||||||
import {DirectoryDTO} from '../../../../../common/entities/DirectoryDTO';
|
import {DirectoryDTO} from '../../../../../common/entities/DirectoryDTO';
|
||||||
@ -229,4 +229,56 @@ describe('GalleryManager', () => {
|
|||||||
expect(selected.media.length).to.deep.equal(subDir.media.length);
|
expect(selected.media.length).to.deep.equal(subDir.media.length);
|
||||||
})).timeout(20000);
|
})).timeout(20000);
|
||||||
|
|
||||||
|
describe('Test listDirectory', () => {
|
||||||
|
const statSync = fs.statSync;
|
||||||
|
let dirTime = 0;
|
||||||
|
const indexedTime = {
|
||||||
|
lastScanned: 0,
|
||||||
|
lastModified: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
dirTime = 0;
|
||||||
|
indexedTime.lastModified = 0;
|
||||||
|
indexedTime.lastScanned = 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
// @ts-ignore
|
||||||
|
fs.statSync = statSync;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with re indexing severity low', async () => {
|
||||||
|
Config.Server.indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
fs.statSync = () => ({ctime: new Date(dirTime), mtime: new Date(dirTime)});
|
||||||
|
const gm = new GalleryManagerTest();
|
||||||
|
gm.selectParentDir = (connection: Connection, directoryName: string, directoryParent: string) => {
|
||||||
|
return Promise.resolve(<any>indexedTime);
|
||||||
|
};
|
||||||
|
gm.fillParentDir = (connection: Connection, dir: DirectoryEntity) => {
|
||||||
|
return Promise.resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
gm.indexDirectory = (...args) => {
|
||||||
|
return <any>Promise.resolve('indexing');
|
||||||
|
};
|
||||||
|
|
||||||
|
indexedTime.lastScanned = null;
|
||||||
|
expect(await gm.listDirectory('./')).to.be.equal('indexing');
|
||||||
|
indexedTime.lastModified = 0;
|
||||||
|
dirTime = 1;
|
||||||
|
expect(await gm.listDirectory('./')).to.be.equal('indexing');
|
||||||
|
indexedTime.lastScanned = 10;
|
||||||
|
indexedTime.lastModified = 1;
|
||||||
|
dirTime = 1;
|
||||||
|
expect(await gm.listDirectory('./')).to.be.equal(indexedTime);
|
||||||
|
expect(await gm.listDirectory('./', 1, 10))
|
||||||
|
.to.be.equal(null);
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -23,11 +23,7 @@ describe('TaskQue', () => {
|
|||||||
tq.add(2);
|
tq.add(2);
|
||||||
const task = tq.get();
|
const task = tq.get();
|
||||||
tq.ready(task);
|
tq.ready(task);
|
||||||
try {
|
expect(tq.isEmpty()).to.be.equal(true);
|
||||||
tq.ready(task);
|
expect(tq.ready.bind(tq, task)).to.be.throw('Task does not exist');
|
||||||
expect(false).to.be.equal(true); // should not reach
|
|
||||||
} catch (e) {
|
|
||||||
expect(e).not.to.be.equal(null);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user