diff --git a/src/Squidex/app/framework/declarations.ts b/src/Squidex/app/framework/declarations.ts index 51fcb48ac..a6ebdcd8c 100644 --- a/src/Squidex/app/framework/declarations.ts +++ b/src/Squidex/app/framework/declarations.ts @@ -56,7 +56,6 @@ export * from './services/analytics.service'; export * from './services/clipboard.service'; export * from './services/dialog.service'; export * from './services/local-store.service'; -export * from './services/local-cache.service'; export * from './services/message-bus.service'; export * from './services/onboarding.service'; export * from './services/resource-loader.service'; diff --git a/src/Squidex/app/framework/module.ts b/src/Squidex/app/framework/module.ts index 1edc0e5a5..ad1a9b076 100644 --- a/src/Squidex/app/framework/module.ts +++ b/src/Squidex/app/framework/module.ts @@ -39,7 +39,6 @@ import { JsonEditorComponent, KeysPipe, KNumberPipe, - LocalCacheService, LocalStoreService, LowerCaseInputDirective, MarkdownEditorComponent, @@ -197,7 +196,6 @@ export class SqxFrameworkModule { CanDeactivateGuard, ClipboardService, DialogService, - LocalCacheService, LocalStoreService, MessageBus, OnboardingService, diff --git a/src/Squidex/app/framework/services/local-cache.service.spec.ts b/src/Squidex/app/framework/services/local-cache.service.spec.ts deleted file mode 100644 index f2380bf6d..000000000 --- a/src/Squidex/app/framework/services/local-cache.service.spec.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Squidex Headless CMS - * - * @license - * Copyright (c) Sebastian Stehle. All rights reserved - */ - -import { LocalCacheService, LocalCacheServiceFactory } from './../'; - -describe('LocalCache', () => { - it('should instantiate from factory', () => { - const localCacheService = LocalCacheServiceFactory(); - - expect(localCacheService).toBeDefined(); - }); - - it('should instantiate', () => { - const localCacheService = new LocalCacheService(); - - expect(localCacheService).toBeDefined(); - }); - - it('should get and store item in cache', () => { - const localCacheService = new LocalCacheService(); - - const value = {}; - - localCacheService.set('key', value); - - expect(localCacheService.get('key')).toBe(value); - }); - - it('should not retrieve item if cleared', () => { - const localCacheService = new LocalCacheService(); - - const value = {}; - - localCacheService.set('key', value); - localCacheService.clear(true); - - expect(localCacheService.get('key')).toBeUndefined(); - }); - - it('should not retrieve item if removed', () => { - const localCacheService = new LocalCacheService(); - - const value = {}; - - localCacheService.set('key', value); - localCacheService.remove('key'); - - expect(localCacheService.get('key')).toBeUndefined(); - }); - - it('should not retrieve item if expired', () => { - const localCacheService = new LocalCacheService(); - - const value = {}; - - localCacheService.set('key', value); - - expect(localCacheService.get('key', new Date().getTime() + 400)).toBeUndefined(); - }); -}); \ No newline at end of file diff --git a/src/Squidex/app/framework/services/local-cache.service.ts b/src/Squidex/app/framework/services/local-cache.service.ts deleted file mode 100644 index 565115f5a..000000000 --- a/src/Squidex/app/framework/services/local-cache.service.ts +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Squidex Headless CMS - * - * @license - * Copyright (c) Sebastian Stehle. All rights reserved - */ - -import { Injectable } from '@angular/core'; - -interface Entry { value: any; expires: number; } - -export const LocalCacheServiceFactory = () => { - return new LocalCacheService(); -}; - -@Injectable() -export class LocalCacheService { - private readonly entries: { [key: string]: Entry } = {}; - - public clear(force: boolean) { - const now = new Date().getTime(); - - for (let key in this.entries) { - if (this.entries.hasOwnProperty(key)) { - const entry = this.entries[key]; - - if (force || LocalCacheService.isExpired(now, entry)) { - delete this.entries[key]; - } - } - } - } - - public get(key: string, now?: number): T | undefined { - const entry = this.entries[key]; - - if (entry) { - now = now || new Date().getTime(); - - if (!LocalCacheService.isExpired(now, entry)) { - delete this.entries[key]; - - return entry.value; - } - } - - return undefined; - } - - public set(key: string, value: T, expiresIn = 100) { - this.entries[key] = { value, expires: new Date().getTime() + expiresIn }; - } - - public remove(key: string) { - delete this.entries[key]; - } - - private static isExpired(now: number, entry: Entry): boolean { - return entry.expires < now; - } -} \ No newline at end of file diff --git a/src/Squidex/app/shared/services/assets.service.spec.ts b/src/Squidex/app/shared/services/assets.service.spec.ts index 25a6bc090..0fdb61ed0 100644 --- a/src/Squidex/app/shared/services/assets.service.spec.ts +++ b/src/Squidex/app/shared/services/assets.service.spec.ts @@ -16,7 +16,6 @@ import { AssetReplacedDto, AssetsService, DateTime, - LocalCacheService, UpdateAssetDto, Version, Versioned @@ -70,7 +69,6 @@ describe('AssetsService', () => { ], providers: [ AssetsService, - LocalCacheService, { provide: ApiUrlConfig, useValue: new ApiUrlConfig('http://service/p/') }, { provide: AnalyticsService, useValue: new AnalyticsService() } ] @@ -216,29 +214,6 @@ describe('AssetsService', () => { new Version('2'))); })); - it('should provide entry from cache if not found', - inject([LocalCacheService, AssetsService, HttpTestingController], (localCache: LocalCacheService, assetsService: AssetsService, httpMock: HttpTestingController) => { - - const cached = {}; - - localCache.set('asset.123', cached, 10000); - - let asset: AssetDto | null = null; - - assetsService.getAsset('my-app', '123').subscribe(result => { - asset = result; - }); - - const req = httpMock.expectOne('http://service/p/api/apps/my-app/assets/123'); - - expect(req.request.method).toEqual('GET'); - expect(req.request.headers.get('If-Match')).toBeNull(); - - req.flush({}, { status: 404, statusText: '404' }); - - expect(asset).toBe(cached); - })); - it('should append query to find by name', inject([AssetsService, HttpTestingController], (assetsService: AssetsService, httpMock: HttpTestingController) => { diff --git a/src/Squidex/app/shared/services/assets.service.ts b/src/Squidex/app/shared/services/assets.service.ts index 5bf2850a7..ce2c3071c 100644 --- a/src/Squidex/app/shared/services/assets.service.ts +++ b/src/Squidex/app/shared/services/assets.service.ts @@ -5,7 +5,7 @@ * Copyright (c) Sebastian Stehle. All rights reserved */ -import { HttpClient, HttpErrorResponse, HttpEventType, HttpHeaders, HttpRequest, HttpResponse } from '@angular/common/http'; +import { HttpClient, HttpEventType, HttpHeaders, HttpRequest, HttpResponse } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; @@ -13,7 +13,6 @@ import { AnalyticsService, ApiUrlConfig, DateTime, - LocalCacheService, HTTP, Version, Versioned @@ -106,8 +105,7 @@ export class AssetsService { constructor( private readonly http: HttpClient, private readonly apiUrl: ApiUrlConfig, - private readonly analytics: AnalyticsService, - private readonly localCache: LocalCacheService + private readonly analytics: AnalyticsService ) { } @@ -202,8 +200,6 @@ export class AssetsService { assetUrl, new Version(event.headers.get('etag'))); - this.localCache.set(`asset.${dto.id}`, dto, 5000); - return dto; } }) @@ -239,17 +235,6 @@ export class AssetsService { assetUrl, response.version); }) - .catch(error => { - if (error instanceof HttpErrorResponse && error.status === 404) { - const cached = this.localCache.get(`asset.${id}`); - - if (cached) { - return Observable.of(cached); - } - } - - return Observable.throw(error); - }) .pretifyError('Failed to load assets. Please reload.'); } @@ -298,8 +283,6 @@ export class AssetsService { return HTTP.deleteVersioned(this.http, url, version) .do(() => { this.analytics.trackEvent('Analytics', 'Deleted', appName); - - this.localCache.remove(`asset.${id}`); }) .pretifyError('Failed to delete asset. Please reload.'); } diff --git a/src/Squidex/app/shared/services/contents.service.spec.ts b/src/Squidex/app/shared/services/contents.service.spec.ts index bc0569cd6..e8ba7abdc 100644 --- a/src/Squidex/app/shared/services/contents.service.spec.ts +++ b/src/Squidex/app/shared/services/contents.service.spec.ts @@ -15,7 +15,6 @@ import { ContentsDto, ContentsService, DateTime, - LocalCacheService, Version } from './../'; @@ -97,7 +96,6 @@ describe('ContentsService', () => { ], providers: [ ContentsService, - LocalCacheService, { provide: ApiUrlConfig, useValue: new ApiUrlConfig('http://service/p/') }, { provide: AnalyticsService, useValue: new AnalyticsService() } ] @@ -166,11 +164,7 @@ describe('ContentsService', () => { it('should append query to get request as search', inject([ContentsService, HttpTestingController], (contentsService: ContentsService, httpMock: HttpTestingController) => { - let contents: ContentsDto | null = null; - - contentsService.getContents('my-app', 'my-schema', 17, 13, 'my-query').subscribe(result => { - contents = result; - }); + contentsService.getContents('my-app', 'my-schema', 17, 13, 'my-query').subscribe(); const req = httpMock.expectOne('http://service/p/api/content/my-app/my-schema?$search="my-query"&$top=17&$skip=13'); @@ -183,11 +177,7 @@ describe('ContentsService', () => { it('should append ids to get request with ids', inject([ContentsService, HttpTestingController], (contentsService: ContentsService, httpMock: HttpTestingController) => { - let contents: ContentsDto | null = null; - - contentsService.getContents('my-app', 'my-schema', 17, 13, undefined, ['id1', 'id2']).subscribe(result => { - contents = result; - }); + contentsService.getContents('my-app', 'my-schema', 17, 13, undefined, ['id1', 'id2']).subscribe(); const req = httpMock.expectOne('http://service/p/api/content/my-app/my-schema?$top=17&$skip=13&ids=id1,id2'); @@ -200,11 +190,7 @@ describe('ContentsService', () => { it('should append query to get request as plain query string', inject([ContentsService, HttpTestingController], (contentsService: ContentsService, httpMock: HttpTestingController) => { - let contents: ContentsDto | null = null; - - contentsService.getContents('my-app', 'my-schema', 17, 13, '$filter=my-filter').subscribe(result => { - contents = result; - }); + contentsService.getContents('my-app', 'my-schema', 17, 13, '$filter=my-filter').subscribe(); const req = httpMock.expectOne('http://service/p/api/content/my-app/my-schema?$filter=my-filter&$top=17&$skip=13'); @@ -250,29 +236,6 @@ describe('ContentsService', () => { new Version('2'))); })); - it('should provide entry from cache if not found', - inject([LocalCacheService, ContentsService, HttpTestingController], (localCache: LocalCacheService, contentsService: ContentsService, httpMock: HttpTestingController) => { - - const cached = {}; - - localCache.set('content.1', cached, 10000); - - let content: ContentDto | null = null; - - contentsService.getContent('my-app', 'my-schema', '1').subscribe(result => { - content = result; - }); - - const req = httpMock.expectOne('http://service/p/api/content/my-app/my-schema/1'); - - expect(req.request.method).toEqual('GET'); - expect(req.request.headers.get('If-Match')).toBeNull(); - - req.flush({}, { status: 404, statusText: '404' }); - - expect(content).toBe(cached); - })); - it('should make post request to create content', inject([ContentsService, HttpTestingController], (contentsService: ContentsService, httpMock: HttpTestingController) => { diff --git a/src/Squidex/app/shared/services/contents.service.ts b/src/Squidex/app/shared/services/contents.service.ts index d0bedab87..bc7706892 100644 --- a/src/Squidex/app/shared/services/contents.service.ts +++ b/src/Squidex/app/shared/services/contents.service.ts @@ -5,7 +5,7 @@ * Copyright (c) Sebastian Stehle. All rights reserved */ -import { HttpClient, HttpErrorResponse } from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; @@ -15,7 +15,6 @@ import { AnalyticsService, ApiUrlConfig, DateTime, - LocalCacheService, HTTP, Version, Versioned @@ -96,8 +95,7 @@ export class ContentsService { constructor( private readonly http: HttpClient, private readonly apiUrl: ApiUrlConfig, - private readonly analytics: AnalyticsService, - private readonly localCache: LocalCacheService + private readonly analytics: AnalyticsService ) { } @@ -172,17 +170,6 @@ export class ContentsService { body.data, response.version); }) - .catch(error => { - if (error instanceof HttpErrorResponse && error.status === 404) { - const cached = this.localCache.get(`content.${id}`); - - if (cached) { - return Observable.of(cached); - } - } - - return Observable.throw(error); - }) .pretifyError('Failed to load content. Please reload.'); } @@ -215,8 +202,6 @@ export class ContentsService { }) .do(content => { this.analytics.trackEvent('Content', 'Created', appName); - - this.localCache.set(`content.${content.id}`, content, 5000); }) .pretifyError('Failed to create content. Please reload.'); } @@ -232,8 +217,6 @@ export class ContentsService { }) .do(() => { this.analytics.trackEvent('Content', 'Updated', appName); - - this.localCache.set(`content.${id}`, dto, 5000); }) .pretifyError('Failed to update content. Please reload.'); } @@ -244,8 +227,6 @@ export class ContentsService { return HTTP.deleteVersioned(this.http, url, version) .do(() => { this.analytics.trackEvent('Content', 'Deleted', appName); - - this.localCache.remove(`content.${id}`); }) .pretifyError('Failed to delete content. Please reload.'); } diff --git a/src/Squidex/app/shared/services/schemas.service.spec.ts b/src/Squidex/app/shared/services/schemas.service.spec.ts index 2f8ec096e..35cd45ae8 100644 --- a/src/Squidex/app/shared/services/schemas.service.spec.ts +++ b/src/Squidex/app/shared/services/schemas.service.spec.ts @@ -16,7 +16,6 @@ import { createProperties, DateTime, FieldDto, - LocalCacheService, SchemaDetailsDto, SchemaDto, SchemaPropertiesDto, @@ -197,7 +196,6 @@ describe('SchemasService', () => { HttpClientTestingModule ], providers: [ - LocalCacheService, SchemasService, { provide: ApiUrlConfig, useValue: new ApiUrlConfig('http://service/p/') }, { provide: AnalyticsService, useValue: new AnalyticsService() } @@ -433,29 +431,6 @@ describe('SchemasService', () => { '')); })); - it('should provide entry from cache if not found', - inject([LocalCacheService, SchemasService, HttpTestingController], (localCache: LocalCacheService, schemasService: SchemasService, httpMock: HttpTestingController) => { - - const cached = {}; - - localCache.set('schema.my-app.my-schema', cached, 10000); - - let schema: SchemaDetailsDto | null = null; - - schemasService.getSchema('my-app', 'my-schema').subscribe(result => { - schema = result; - }); - - const req = httpMock.expectOne('http://service/p/api/apps/my-app/schemas/my-schema'); - - expect(req.request.method).toEqual('GET'); - expect(req.request.headers.get('If-Match')).toBeNull(); - - req.flush({}, { status: 404, statusText: '404' }); - - expect(schema).toBe(cached); - })); - it('should make post request to create schema', inject([SchemasService, HttpTestingController], (schemasService: SchemasService, httpMock: HttpTestingController) => { diff --git a/src/Squidex/app/shared/services/schemas.service.ts b/src/Squidex/app/shared/services/schemas.service.ts index c5904552d..440b11b18 100644 --- a/src/Squidex/app/shared/services/schemas.service.ts +++ b/src/Squidex/app/shared/services/schemas.service.ts @@ -5,7 +5,7 @@ * Copyright (c) Sebastian Stehle. All rights reserved */ -import { HttpClient, HttpErrorResponse } from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { ValidatorFn, Validators } from '@angular/forms'; import { Observable } from 'rxjs'; @@ -16,7 +16,6 @@ import { AnalyticsService, ApiUrlConfig, DateTime, - LocalCacheService, HTTP, ValidatorsEx, Version, @@ -786,8 +785,7 @@ export class SchemasService { constructor( private readonly http: HttpClient, private readonly apiUrl: ApiUrlConfig, - private readonly analytics: AnalyticsService, - private readonly localCache: LocalCacheService + private readonly analytics: AnalyticsService ) { } @@ -858,17 +856,6 @@ export class SchemasService { body.scriptDelete, body.scriptChange); }) - .catch(error => { - if (error instanceof HttpErrorResponse && error.status === 404) { - const cached = this.localCache.get(`schema.${appName}.${id}`); - - if (cached) { - return Observable.of(cached); - } - } - - return Observable.throw(error); - }) .pretifyError('Failed to load schema. Please reload.'); } @@ -900,9 +887,6 @@ export class SchemasService { }) .do(schema => { this.analytics.trackEvent('Schema', 'Created', appName); - - this.localCache.set(`schema.${appName}.${schema.id}`, schema, 5000); - this.localCache.set(`schema.${appName}.${schema.name}`, schema, 5000); }) .pretifyError('Failed to create schema. Please reload.'); } @@ -935,9 +919,6 @@ export class SchemasService { const url = this.apiUrl.buildUrl(`api/apps/${appName}/schemas/${schemaName}`); return HTTP.deleteVersioned(this.http, url, version) - .do(() => { - this.localCache.remove(`schema.${appName}.${schemaName}`); - }) .do(() => { this.analytics.trackEvent('Schema', 'Deleted', appName); }) diff --git a/src/Squidex/package.json b/src/Squidex/package.json index 8ea7b3e2b..7e6427fb0 100644 --- a/src/Squidex/package.json +++ b/src/Squidex/package.json @@ -15,36 +15,36 @@ "build:clean": "rimraf wwwroot/build" }, "dependencies": { - "@angular/animations": "5.0.5", - "@angular/common": "5.0.5", - "@angular/compiler": "5.0.5", - "@angular/core": "5.0.5", - "@angular/forms": "5.0.5", - "@angular/http": "5.0.5", - "@angular/platform-browser": "5.0.5", - "@angular/platform-browser-dynamic": "5.0.5", - "@angular/platform-server": "5.0.5", - "@angular/router": "5.0.5", + "@angular/animations": "5.1.0", + "@angular/common": "5.1.0", + "@angular/compiler": "5.1.0", + "@angular/core": "5.1.0", + "@angular/forms": "5.1.0", + "@angular/http": "5.1.0", + "@angular/platform-browser": "5.1.0", + "@angular/platform-browser-dynamic": "5.1.0", + "@angular/platform-server": "5.1.0", + "@angular/router": "5.1.0", "angular2-chartjs": "0.4.1", "babel-polyfill": "6.26.0", "bootstrap": "4.0.0-alpha.6", - "core-js": "2.5.1", + "core-js": "2.5.3", "graphiql": "0.11.10", - "moment": "2.19.3", + "moment": "2.19.4", "mousetrap": "1.6.1", "ng2-dnd": "5.0.2", "oidc-client": "1.4.1", - "pikaday": "1.6.1", + "pikaday": "1.7.0", "progressbar.js": "1.0.1", "react": "16.2.0", "react-dom": "16.2.0", - "rxjs": "5.5.2", + "rxjs": "5.5.5", "zone.js": "0.8.18" }, "devDependencies": { - "@angular/compiler": "5.0.5", - "@angular/compiler-cli": "5.0.5", - "@ngtools/webpack": "1.8.5", + "@angular/compiler": "5.1.0", + "@angular/compiler-cli": "5.1.0", + "@ngtools/webpack": "1.9.0", "@types/core-js": "0.9.35", "@types/jasmine": "2.5.45", "@types/mousetrap": "1.5.34", @@ -54,7 +54,7 @@ "angular2-router-loader": "0.3.5", "angular2-template-loader": "0.6.2", "awesome-typescript-loader": "3.4.1", - "codelyzer": "4.0.1", + "codelyzer": "4.0.2", "cpx": "1.5.0", "css-loader": "0.28.7", "exports-loader": "0.6.4", @@ -88,10 +88,10 @@ "tslint": "5.8.0", "tslint-loader": "3.5.3", "typemoq": "2.1.0", - "typescript": "2.4.2", + "typescript": "2.5.3", "underscore": "1.8.3", - "webpack": "3.9.1", - "webpack-dev-server": "2.9.5", + "webpack": "3.10.0", + "webpack-dev-server": "2.9.7", "webpack-merge": "4.1.1" } } diff --git a/tools/Migrate_01/Migration01.cs b/tools/Migrate_01/Migration01.cs index 7bc699334..c0a8c9e2e 100644 --- a/tools/Migrate_01/Migration01.cs +++ b/tools/Migrate_01/Migration01.cs @@ -56,8 +56,14 @@ namespace Migrate_01 { var subscription = eventStore.CreateSubscription(this, ".*"); - await subscriptionTcs.Task; - await subscription.StopAsync(); + try + { + await subscriptionTcs.Task; + } + finally + { + await subscription.StopAsync(); + } } public async Task OnEventAsync(IEventSubscription subscription, StoredEvent storedEvent)