diff --git a/client/src/app/core/local-storage/custom-indexeddb-database.ts b/client/src/app/core/local-storage/custom-indexeddb-database.ts index 1bc4cca19..9be5c5fbc 100644 --- a/client/src/app/core/local-storage/custom-indexeddb-database.ts +++ b/client/src/app/core/local-storage/custom-indexeddb-database.ts @@ -66,7 +66,7 @@ export class CustomIndexedDBDatabase extends IndexedDBDatabase { } else { // Storing the database connection for further access this.database.next(db); - this.storageLock.OK(); + this.storageLock.OK(true); } }, () => { @@ -80,7 +80,7 @@ export class CustomIndexedDBDatabase extends IndexedDBDatabase { public setFallback(prefix: string): void { console.log('uses localStorage as IndexedDB fallback!'); super.setFallback(prefix); - this.storageLock.OK(); + this.storageLock.OK(false); } } diff --git a/client/src/app/core/local-storage/storagelock.service.ts b/client/src/app/core/local-storage/storagelock.service.ts index 810ed9302..6218367d8 100644 --- a/client/src/app/core/local-storage/storagelock.service.ts +++ b/client/src/app/core/local-storage/storagelock.service.ts @@ -9,16 +9,22 @@ import { Injectable } from '@angular/core'; export class StoragelockService { private lock: Promise; private resolve: () => void; + private _indexedDBUsed = false; public get promise(): Promise { return this.lock; } + public get indexedDBUsed(): boolean { + return this._indexedDBUsed; + } + public constructor() { this.lock = new Promise(resolve => (this.resolve = resolve)); } - public OK(): void { + public OK(indexedDBUsed: boolean): void { + this._indexedDBUsed = indexedDBUsed; this.resolve(); } } diff --git a/client/src/app/core/ui-services/count-users.service.ts b/client/src/app/core/ui-services/count-users.service.ts index fb2698a2e..d983e8af3 100644 --- a/client/src/app/core/ui-services/count-users.service.ts +++ b/client/src/app/core/ui-services/count-users.service.ts @@ -4,13 +4,19 @@ import { Observable, Subject } from 'rxjs'; import { NotifyService } from '../core-services/notify.service'; import { OperatorService } from '../core-services/operator.service'; +import { StoragelockService } from '../local-storage/storagelock.service'; interface CountUserRequest { token: string; } -interface CountUserResponse extends CountUserRequest { +export interface CountUserData { userId: number; + usesIndexedDB: boolean; +} + +interface CountUserResponse extends CountUserRequest { + data: CountUserData; } const REQUEST_NAME = 'count-user-request'; @@ -25,7 +31,7 @@ const RESPONSE_NAME = 'count-user-response'; providedIn: 'root' }) export class CountUsersService { - private activeCounts: { [token: string]: Subject } = {}; + private activeCounts: { [token: string]: Subject } = {}; private currentUserId: number; @@ -35,15 +41,22 @@ export class CountUsersService { * @param notifyService * @param operator */ - public constructor(private notifyService: NotifyService, operator: OperatorService) { + public constructor( + private notifyService: NotifyService, + operator: OperatorService, + storageLockService: StoragelockService + ) { // Listen for requests to send an answer. this.notifyService.getMessageObservable(REQUEST_NAME).subscribe(request => { if (request.content.token) { - this.notifyService.sendToChannels( + this.notifyService.sendToChannels( RESPONSE_NAME, { token: request.content.token, - userId: this.currentUserId + data: { + userId: this.currentUserId, + usesIndexedDB: storageLockService.indexedDBUsed + } }, request.senderChannelName ); @@ -52,8 +65,8 @@ export class CountUsersService { // Listen for responses and distribute them through `activeCounts` this.notifyService.getMessageObservable(RESPONSE_NAME).subscribe(response => { - if (response.content.userId && response.content.token && this.activeCounts[response.content.token]) { - this.activeCounts[response.content.token].next(response.content.userId); + if (response.content.data && response.content.token && this.activeCounts[response.content.token]) { + this.activeCounts[response.content.token].next(response.content.data); } }); @@ -80,9 +93,9 @@ export class CountUsersService { * counting with `stopCounting`. The second entry is an observable, where all user * ids will be published. */ - public countUsers(): [string, Observable] { + public countUsers(): [string, Observable] { const trackToken = this.generateTrackToken(); - const subject = new Subject(); + const subject = new Subject(); this.activeCounts[trackToken] = subject; this.notifyService.sendToAllUsers(REQUEST_NAME, { token: trackToken diff --git a/client/src/app/site/common/components/count-users/count-users.component.html b/client/src/app/site/common/components/count-users/count-users.component.html index 4b088e3e8..7350ec698 100644 --- a/client/src/app/site/common/components/count-users/count-users.component.html +++ b/client/src/app/site/common/components/count-users/count-users.component.html @@ -8,6 +8,8 @@

{{ userIds().length }} active users + ({{ stats.usesIndexedDB }} with indexedDB, + {{ stats.activeUserHandles-stats.usesIndexedDB }} with local storage) ({{ stats.activeUserHandles }} connections)

Groups

diff --git a/client/src/app/site/common/services/count-user-statistics.service.ts b/client/src/app/site/common/services/count-user-statistics.service.ts index 6180af78a..3bdf33679 100644 --- a/client/src/app/site/common/services/count-user-statistics.service.ts +++ b/client/src/app/site/common/services/count-user-statistics.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; -import { CountUsersService } from 'app/core/ui-services/count-users.service'; +import { CountUsersService, CountUserData } from 'app/core/ui-services/count-users.service'; import { Observable, BehaviorSubject } from 'rxjs'; import { UserRepositoryService } from 'app/core/repositories/users/user-repository.service'; @@ -9,6 +9,7 @@ import { UserRepositoryService } from 'app/core/repositories/users/user-reposito */ export interface CountUserStatistics { activeUserHandles: number; + usesIndexedDB: number; activeUsers: { [id: number]: number; }; @@ -42,25 +43,31 @@ export class CountUsersStatisticsService { */ public countUsers(): [string, Observable] { let token: string; - let userIdObservable: Observable; + let userDataObservable: Observable; // Start counting // TODO: maybe we shold bet the observable bofore the actual countig was // started. We might miss some user ids. - [token, userIdObservable] = this.countUserService.countUsers(); + [token, userDataObservable] = this.countUserService.countUsers(); this.runningCounts[token] = new BehaviorSubject({ activeUserHandles: 0, + usesIndexedDB: 0, activeUsers: {}, groups: {} }); // subscribe to responses - userIdObservable.subscribe(userId => { + userDataObservable.subscribe(data => { + const userId = !!data.userId ? data.userId : 0; + const stats = this.runningCounts[token].getValue(); const user = this.userRepo.getViewModel(userId); // Add to user stats stats.activeUserHandles++; + if (data.usesIndexedDB) { + stats.usesIndexedDB++; + } if (!stats.activeUsers[userId]) { stats.activeUsers[userId] = 0; }