improving content caching

This commit is contained in:
Patrik Braun 2017-07-28 00:04:19 +02:00
parent 1d7bc3c489
commit 393731133c
9 changed files with 28 additions and 15 deletions

View File

@ -42,7 +42,7 @@ export class RenderingMWs {
if (!req.resultPipe) if (!req.resultPipe)
return next(); return next();
return res.sendFile(req.resultPipe); return res.sendFile(req.resultPipe, {maxAge: 31536000});
} }
public static renderOK(req: Request, res: Response, next: NextFunction) { public static renderOK(req: Request, res: Response, next: NextFunction) {

View File

@ -10,7 +10,7 @@ export class PublicRouter {
public static route(app) { public static route(app) {
const renderIndex = (req: Request, res: Response) => { const renderIndex = (req: Request, res: Response) => {
res.sendFile(_path.resolve(__dirname, './../../dist/index.html')); res.sendFile(_path.resolve(ProjectPath.FrontendFolder, 'index.html'), {maxAge: 31536000});
}; };
app.use( app.use(
@ -29,18 +29,16 @@ export class PublicRouter {
}); });
app.get('/config_inject.js', (req: Request, res: Response) => { app.get('/config_inject.js', (req: Request, res: Response) => {
res.render(_path.resolve(__dirname, './../../dist/config_inject.ejs'), res.tpl); res.render(_path.resolve(ProjectPath.FrontendFolder, 'config_inject.ejs'), res.tpl);
}); });
app.get(['/', '/login', "/gallery*", "/share*", "/admin", "/search*"], app.get(['/', '/login', "/gallery*", "/share*", "/admin", "/search*"],
AuthenticationMWs.tryAuthenticate, AuthenticationMWs.tryAuthenticate,
renderIndex renderIndex
); );
app.use(_express.static(ProjectPath.FrontendFolder)); app.use(_express.static(ProjectPath.FrontendFolder, {maxAge: 31536000}));
app.use('/node_modules', _express.static(_path.resolve(__dirname, './../../node_modules'))); // app.use('/node_modules', _express.static(_path.resolve(__dirname, './../../node_modules')));
app.use('/common', _express.static(_path.resolve(__dirname, './../../common'))); // app.use('/common', _express.static(_path.resolve(__dirname, './../../common')));
} }
} }

View File

@ -42,7 +42,7 @@ export class PrivateConfigClass extends PublicConfigClass implements IPrivateCon
indexing: { indexing: {
folderPreviewSize: 2, folderPreviewSize: 2,
cachedFolderTimeout: 1000 * 60 * 60, cachedFolderTimeout: 1000 * 60 * 60,
reIndexingSensitivity: ReIndexingSensitivity.high reIndexingSensitivity: ReIndexingSensitivity.medium
}, },
enableThreading: true enableThreading: true
}; };

View File

@ -81,6 +81,7 @@ export class GalleryService {
return null return null
} }
this.content.next(null);
const cw: ContentWrapper = await this.networkService.getJson<ContentWrapper>("/search/" + text, {type: type}); const cw: ContentWrapper = await this.networkService.getJson<ContentWrapper>("/search/" + text, {type: type});
console.log("photos", cw.searchResult.photos.length); console.log("photos", cw.searchResult.photos.length);
console.log("direcotries", cw.searchResult.directories.length); console.log("direcotries", cw.searchResult.directories.length);
@ -106,7 +107,7 @@ export class GalleryService {
this.searchId = setTimeout(() => { this.searchId = setTimeout(() => {
this.search(text); this.search(text);
this.searchId = null; this.searchId = null;
}, Config.Client.Search.InstantSearchTimeout); //TODO: set timeout to config }, Config.Client.Search.InstantSearchTimeout);
const cw = await this.networkService.getJson<ContentWrapper>("/instant-search/" + text); const cw = await this.networkService.getJson<ContentWrapper>("/instant-search/" + text);
this.content.next(cw); this.content.next(cw);

View File

@ -404,6 +404,9 @@ export class GalleryLightboxComponent implements OnDestroy {
public play() { public play() {
this.pause(); this.pause();
this.timerSub = this.timer.filter(t => t % 2 == 0).subscribe(() => { this.timerSub = this.timer.filter(t => t % 2 == 0).subscribe(() => {
if (this.photoElement.imageLoadFinished == false) {
return;
}
if (this.navigation.hasNext) { if (this.navigation.hasNext) {
this.nextImage(); this.nextImage();
} else { } else {
@ -416,6 +419,9 @@ export class GalleryLightboxComponent implements OnDestroy {
public fastForward() { public fastForward() {
this.pause(); this.pause();
this.timerSub = this.timer.subscribe(() => { this.timerSub = this.timer.subscribe(() => {
if (this.photoElement.imageLoadFinished == false) {
return;
}
if (this.navigation.hasNext) { if (this.navigation.hasNext) {
this.nextImage(); this.nextImage();
} else { } else {

View File

@ -15,6 +15,7 @@ export class GalleryLightboxPhotoComponent implements OnChanges {
public imageSize = {width: "auto", height: "100"}; public imageSize = {width: "auto", height: "100"};
imageLoaded: boolean = false; imageLoaded: boolean = false;
public imageLoadFinished: boolean = false;
constructor(public elementRef: ElementRef) { constructor(public elementRef: ElementRef) {
} }
@ -22,6 +23,7 @@ export class GalleryLightboxPhotoComponent implements OnChanges {
ngOnChanges() { ngOnChanges() {
this.imageLoaded = false; this.imageLoaded = false;
this.imageLoadFinished = false;
this.setImageSize(); this.setImageSize();
} }
@ -44,11 +46,13 @@ export class GalleryLightboxPhotoComponent implements OnChanges {
onImageLoad() { onImageLoad() {
this.imageLoadFinished = true;
this.imageLoaded = true; this.imageLoaded = true;
} }
onImageError() { onImageError() {
//TODO:handle error //TODO:handle error
this.imageLoadFinished = true;
console.error("cant load image"); console.error("cant load image");
} }

View File

@ -31,7 +31,7 @@ export class GalleryShareComponent implements OnInit, OnDestroy {
}; };
validityTypes = []; validityTypes = [];
currentDir: string = ""; currentDir: string = "";
sharing: SharingDTO; sharing: SharingDTO = null;
contentSubscription = null; contentSubscription = null;
passwordProtection = false; passwordProtection = false;
@ -76,6 +76,9 @@ export class GalleryShareComponent implements OnInit, OnDestroy {
} }
async update() { async update() {
if (this.sharing == null) {
return;
}
this.url = "loading.."; this.url = "loading..";
this.sharing = await this._sharingService.updateSharing(this.currentDir, this.sharing.id, this.input.includeSubfolders, this.input.password, this.calcValidity()); this.sharing = await this._sharingService.updateSharing(this.currentDir, this.sharing.id, this.input.includeSubfolders, this.input.password, this.calcValidity());
console.log(this.sharing); console.log(this.sharing);

View File

@ -9,7 +9,8 @@ import {AbstractSettingsService} from "./abstract.settings.service";
import {IPrivateConfig} from "../../../../common/config/private/IPrivateConfig"; import {IPrivateConfig} from "../../../../common/config/private/IPrivateConfig";
export abstract class SettingsComponent<T> implements OnInit, OnDestroy, OnChanges { export abstract class SettingsComponent<T, S extends AbstractSettingsService<T>=AbstractSettingsService<T>>
implements OnInit, OnDestroy, OnChanges {
@Input() @Input()
public simplifiedMode: boolean = true; public simplifiedMode: boolean = true;
@ -32,7 +33,7 @@ export abstract class SettingsComponent<T> implements OnInit, OnDestroy, OnChang
constructor(private name, constructor(private name,
private _authService: AuthenticationService, private _authService: AuthenticationService,
private _navigation: NavigationService, private _navigation: NavigationService,
public _settingsService: AbstractSettingsService<T>, public _settingsService: S,
protected notification: NotificationService, protected notification: NotificationService,
private sliceFN?: (s: IPrivateConfig) => T) { private sliceFN?: (s: IPrivateConfig) => T) {
if (this.sliceFN) { if (this.sliceFN) {

View File

@ -16,7 +16,7 @@ import {Utils} from "../../../../common/Utils";
'./../_abstract/abstract.settings.component.css'], './../_abstract/abstract.settings.component.css'],
providers: [IndexingSettingsService], providers: [IndexingSettingsService],
}) })
export class IndexingSettingsComponent extends SettingsComponent<IndexingConfig> { export class IndexingSettingsComponent extends SettingsComponent<IndexingConfig, IndexingSettingsService> {
types: Array<any> = []; types: Array<any> = [];
@ -79,7 +79,7 @@ export class IndexingSettingsComponent extends SettingsComponent<IndexingConfig>
this.inProgress = true; this.inProgress = true;
this.error = ""; this.error = "";
try { try {
await (<IndexingSettingsService>this._settingsService).index(); await this._settingsService.index();
this.updateProgress(); this.updateProgress();
this.notification.success("Folder indexed", "Success"); this.notification.success("Folder indexed", "Success");
this.inProgress = false; this.inProgress = false;