Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this may be inefficient with large number of users #117

Open
github-actions bot opened this issue Feb 17, 2024 · 0 comments
Open

this may be inefficient with large number of users #117

github-actions bot opened this issue Feb 17, 2024 · 0 comments
Labels
todo Todo command inside code

Comments

@github-actions
Copy link

// TODO this may be inefficient with large number of users

import {Participant, Poll, PollEvent, StatisticsDto} from '@apollusia/types';
import {Injectable} from '@nestjs/common';
import {InjectModel} from '@nestjs/mongoose';
import {Model} from 'mongoose';

@Injectable()
export class StatisticsService {
    constructor(
        @InjectModel(Poll.name) private pollModel: Model<Poll>,
        @InjectModel(PollEvent.name) private pollEventModel: Model<PollEvent>,
        @InjectModel(Participant.name) private participantModel: Model<Participant>,
    ) {
    }

    async getStats(): Promise<StatisticsDto> {
        const [
            polls,
            pollEvents,
            participants,
            pollTokens,
            participantTokens,
        ] = await Promise.all([
            this.pollModel.countDocuments().exec(),
            this.pollEventModel.countDocuments().exec(),
            this.participantModel.countDocuments().exec(),
            this.pollModel.distinct('token').exec(),
            this.participantModel.distinct('token').exec(),
        ]);
        return {
            polls,
            pollEvents,
            participants,
            // TODO this may be inefficient with large number of users
            users: new Set([...pollTokens, ...participantTokens]).size,
        };
    }
}
@github-actions github-actions bot added the todo Todo command inside code label Feb 17, 2024
@Clashsoft Clashsoft moved this to Backlog in Apollusia Feb 17, 2024
@Clashsoft Clashsoft removed their assignment Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
todo Todo command inside code
Projects
Status: Backlog
Development

No branches or pull requests

1 participant