Skip to content

Commit

Permalink
Add optional domain parameter to get attendance functions to eliminate
Browse files Browse the repository at this point in the history
    refetch of domain.
  • Loading branch information
Misterblue committed Feb 4, 2021
1 parent d6eaf01 commit 40a3a4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions src/Entities/Places.ts
Expand Up @@ -35,6 +35,7 @@ import { createObject, getObject, getObjects, updateObjectFields, deleteOne, del
import { GenUUID, IsNullOrEmpty, IsNotNullOrEmpty, genRandomString } from '@Tools/Misc';
import { VKeyedCollection } from '@Tools/vTypes';
import { Logger } from '@Tools/Logging';
import { DomainEntity } from './DomainEntity';

export let placeCollection = 'places';

Expand Down Expand Up @@ -119,7 +120,7 @@ export const Places = {
return updateObjectFields(placeCollection,
new GenericFilter({ 'id': pEntity.id }), pFields);
},
async getCurrentAttendance(pPlace: PlaceEntity): Promise<number> {
async getCurrentAttendance(pPlace: PlaceEntity, pDomain?: DomainEntity): Promise<number> {
// Attendance is either reported by a beacon script or defaults to the domain's numbers
// If the last current update is stale (older than a few minutes), the domain's number is used
let attendance: number = 0;
Expand All @@ -132,12 +133,15 @@ export const Places = {
};
if (useDomain) {
// There isn't current attendance info. Default to domain's numbers
if (IsNullOrEmpty(pPlace.domainId)) {
const aDomain = await Domains.getDomainWithId(pPlace.domainId);
if (IsNotNullOrEmpty(aDomain)) {
attendance = (aDomain.numUsers ?? 0) + (aDomain.anonUsers ?? 0);
let aDomain = pDomain;
if (IsNullOrEmpty(aDomain)) {
if (IsNotNullOrEmpty(pPlace.domainId)) {
aDomain = await Domains.getDomainWithId(pPlace.domainId);
};
};
if (IsNotNullOrEmpty(aDomain)) {
attendance = (aDomain.numUsers ?? 0) + (aDomain.anonUsers ?? 0);
};
};
return attendance;

Expand Down
6 changes: 3 additions & 3 deletions src/route-tools/Util.ts
Expand Up @@ -251,7 +251,7 @@ export async function buildAccountProfile(pReq: Request, pAccount: AccountEntity
// Return an object with the formatted place information
// Pass the PlaceEntity and the place's domain if known.
export async function buildPlaceInfo(pPlace: PlaceEntity, pDomain?: DomainEntity): Promise<any> {
const ret = await buildPlaceInfoSmall(pPlace);
const ret = await buildPlaceInfoSmall(pPlace, pDomain);

// if the place points to a domain, add that information also
if (IsNotNullOrEmpty(pPlace.domainId)) {
Expand All @@ -263,7 +263,7 @@ export async function buildPlaceInfo(pPlace: PlaceEntity, pDomain?: DomainEntity
return ret;
};
// Return the basic information block for a Place
export async function buildPlaceInfoSmall(pPlace: PlaceEntity): Promise<any> {
export async function buildPlaceInfoSmall(pPlace: PlaceEntity, pDomain?: DomainEntity): Promise<any> {
const ret: VKeyedCollection = {
'placeId': pPlace.id,
'id': pPlace.id,
Expand All @@ -275,7 +275,7 @@ export async function buildPlaceInfoSmall(pPlace: PlaceEntity): Promise<any> {
'tags': pPlace.tags,
'thumbnail': pPlace.thumbnail,
'images': pPlace.images,
'current_attendance': await Places.getCurrentAttendance(pPlace),
'current_attendance': await Places.getCurrentAttendance(pPlace, pDomain),
'current_images': pPlace.currentImages,
'current_info': pPlace.currentInfo,
'current_last_update_time': pPlace.currentLastUpdateTime
Expand Down

0 comments on commit 40a3a4f

Please sign in to comment.