From 7d8372131fde8ea8c52174592b2055749bb20abe Mon Sep 17 00:00:00 2001 From: Artem Niehrieiev Date: Tue, 9 Sep 2025 12:12:26 +0000 Subject: [PATCH] refactor: remove unused method getConnectionsWithNonNullUsersGCLIDs and simplify getWorkedConnectionsInTwoWeeks --- .../connection.repository.interface.ts | 2 - .../custom-connection-repository-extension.ts | 44 ++++--------------- .../user-custom-repository-extension.ts | 3 +- 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/backend/src/entities/connection/repository/connection.repository.interface.ts b/backend/src/entities/connection/repository/connection.repository.interface.ts index eb5db8c30..f4a76e21d 100644 --- a/backend/src/entities/connection/repository/connection.repository.interface.ts +++ b/backend/src/entities/connection/repository/connection.repository.interface.ts @@ -20,8 +20,6 @@ export interface IConnectionRepository { findConnectionWithGroups(connectionId: string): Promise; - getConnectionsWithNonNullUsersGCLIDs(): Promise>; - getWorkedConnectionsInTwoWeeks(): Promise>; getConnectionByGroupIdWithCompanyAndUsersInCompany(groupId: string): Promise; diff --git a/backend/src/entities/connection/repository/custom-connection-repository-extension.ts b/backend/src/entities/connection/repository/custom-connection-repository-extension.ts index 8623dbb0d..7bdc1bcac 100644 --- a/backend/src/entities/connection/repository/custom-connection-repository-extension.ts +++ b/backend/src/entities/connection/repository/custom-connection-repository-extension.ts @@ -2,7 +2,6 @@ import { Messages } from '../../../exceptions/text/messages.js'; import { Constants } from '../../../helpers/constants/constants.js'; import { Encryptor } from '../../../helpers/encryption/encryptor.js'; import { isConnectionTypeAgent } from '../../../helpers/index.js'; -import { TableLogsEntity } from '../../table-logs/table-logs.entity.js'; import { UserEntity } from '../../user/user.entity.js'; import { ConnectionEntity } from '../connection.entity.js'; import { isTestConnectionUtil } from '../utils/is-test-connection-util.js'; @@ -128,41 +127,16 @@ export const customConnectionRepositoryExtension: IConnectionRepository = { return await qb.getOne(); }, - async getConnectionsWithNonNullUsersGCLIDs(): Promise> { - const dateTwoWeeksAgo = Constants.TWO_WEEKS_AGO(); - const connectionsQB = this.createQueryBuilder('connection') - .where('connection.createdAt > :date', { date: dateTwoWeeksAgo }) - .leftJoinAndSelect('connection.author', 'user') - .andWhere('user.gclid IS NOT NULL'); - const freshConnections: Array = await connectionsQB.getMany(); - const testConnectionsHosts = Constants.getTestConnectionsArr().map((connection) => { - return connection.host; - }); - return freshConnections.filter((connection: ConnectionEntity) => { - return !testConnectionsHosts.includes(connection.host); - }); - }, - async getWorkedConnectionsInTwoWeeks(): Promise> { - const freshConnections = await this.getConnectionsWithNonNullUsersGCLIDs(); - const workedFreshConnections: Array = await Promise.all( - freshConnections.map(async (connection: ConnectionEntity): Promise => { - const qb = this.manager - .getRepository(TableLogsEntity) - .createQueryBuilder('tableLogs') - .leftJoinAndSelect('tableLogs.connection_id', 'connection_id'); - qb.andWhere('tableLogs.connection_id = :connection_id', { connection_id: connection.id }); - const logs = await qb.getMany(); - if (logs && logs.length > 0) { - return connection; - } else { - return null; - } - }), - ); - return workedFreshConnections.filter((connection) => { - return !!connection; - }); + const freshNonTestConnectionsWithLogs = await this.createQueryBuilder('connection') + .leftJoinAndSelect('connection.author', 'author') + .leftJoin('connection.logs', 'logs') + .where('connection.createdAt > :date', { date: Constants.TWO_WEEKS_AGO() }) + .andWhere('author.gclid IS NOT NULL') + .andWhere('connection.isTestConnection = :isTest', { isTest: false }) + .andWhere('logs.id IS NOT NULL') + .getMany(); + return freshNonTestConnectionsWithLogs; }, async getConnectionByGroupIdWithCompanyAndUsersInCompany(groupId: string): Promise { diff --git a/backend/src/entities/user/repository/user-custom-repository-extension.ts b/backend/src/entities/user/repository/user-custom-repository-extension.ts index cbf9149e8..d36a37308 100644 --- a/backend/src/entities/user/repository/user-custom-repository-extension.ts +++ b/backend/src/entities/user/repository/user-custom-repository-extension.ts @@ -118,7 +118,8 @@ export const userCustomRepositoryExtension: IUserRepository = { const dateTwoWeeksAgo = Constants.TWO_WEEKS_AGO(); const usersQB = this.createQueryBuilder('user') .where('user.createdAt > :date', { date: dateTwoWeeksAgo }) - .andWhere('user.gclid IS NOT NULL'); + .andWhere('user.gclid IS NOT NULL') + .andWhere('user.isDemoAccount = :isDemo', { isDemo: false }); return await usersQB.getMany(); },