📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
perf: use COUNT query instead of loading all projects to check limit
Blue Mouse662dfd2bb909
diff --git a/backend/apps/cloud/src/project/project.controller.ts b/backend/apps/cloud/src/project/project.controller.tsindex ecb1d46d6..80b6a697f 100644--- a/backend/apps/cloud/src/project/project.controller.ts+++ b/backend/apps/cloud/src/project/project.controller.ts@@ -312,7 +312,6 @@ export class ProjectController {const initiatingUser = await this.userService.findOne({where: { id: userId },- relations: ['projects'],})const { maxProjects = PROJECTS_MAXIMUM } = initiatingUser@@ -349,7 +348,9 @@ export class ProjectController {)}- if (_size(user.projects) >= maxProjects) {+ const projectCount = await this.projectService.countByAdminId(user.id)++ if (projectCount >= maxProjects) {throw new ForbiddenException(`You cannot create more than ${maxProjects} projects on your account plan. Please upgrade to be able to create more projects.`,)@@ -419,7 +420,6 @@ export class ProjectController {const user = await this.userService.findOne({where: { id: userId },- relations: ['projects'],})if (!user.isActive) {@@ -476,7 +476,6 @@ export class ProjectController {const user = await this.userService.findOne({where: { id: userId },- relations: ['projects'],})if (!user.isActive) {@@ -617,7 +616,6 @@ export class ProjectController {const user = await this.userService.findOne({where: { id: userId },- relations: ['projects'],})if (!user.isActive) {@@ -660,7 +658,6 @@ export class ProjectController {const user = await this.userService.findOne({where: { id: userId },- relations: ['projects'],})if (!user.isActive) {diff --git a/backend/apps/cloud/src/project/project.service.ts b/backend/apps/cloud/src/project/project.service.tsindex 4aeb436ad..1fcc0117b 100644--- a/backend/apps/cloud/src/project/project.service.ts+++ b/backend/apps/cloud/src/project/project.service.ts@@ -594,6 +594,10 @@ export class ProjectService implements OnModuleDestroy {return this.projectsRepository.count()}+ async countByAdminId(adminId: string): Promise<number> {+ return this.projectsRepository.count({ where: { admin: { id: adminId } } })+ }+async create(project: DeepPartial<Project>) {return this.projectsRepository.save(project)}