diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index d66f729db..4553d13c8 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -12,7 +12,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0086-add_community_location', + DB_VERSION: '0087-add_index_on_user_roles', DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 4e1504b02..bed9a5d94 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -972,16 +972,15 @@ export class UserResolver { } export async function findUserByEmail(email: string): Promise { - const dbUserContact = await DbUserContact.findOneOrFail({ - where: { email }, + const dbUser = await DbUser.findOneOrFail({ + where: { + emailContact: { email }, + }, withDeleted: true, - relations: ['user'], + relations: { userRoles: true, emailContact: true }, }).catch(() => { throw new LogError('No user with this credentials', email) }) - const dbUser = dbUserContact.user - dbUser.emailContact = dbUserContact - dbUser.userRoles = await UserRole.find({ where: { userId: dbUser.id } }) return dbUser } diff --git a/database/migrations/0087-add_index_on_user_roles.ts b/database/migrations/0087-add_index_on_user_roles.ts new file mode 100644 index 000000000..40d49ccbf --- /dev/null +++ b/database/migrations/0087-add_index_on_user_roles.ts @@ -0,0 +1,10 @@ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn('ALTER TABLE `user_roles` ADD INDEX user_id (user_id);') +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn('ALTER TABLE `user_roles` DROP INDEX `user_id`;') +} diff --git a/dht-node/src/config/index.ts b/dht-node/src/config/index.ts index 8bf59c465..70ec452bf 100644 --- a/dht-node/src/config/index.ts +++ b/dht-node/src/config/index.ts @@ -4,7 +4,7 @@ import dotenv from 'dotenv' dotenv.config() const constants = { - DB_VERSION: '0086-add_community_location', + DB_VERSION: '0087-add_index_on_user_roles', LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info LOG_LEVEL: process.env.LOG_LEVEL ?? 'info', diff --git a/federation/src/config/index.ts b/federation/src/config/index.ts index 0cbebc733..4f72859c1 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -10,7 +10,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0086-add_community_location', + DB_VERSION: '0087-add_index_on_user_roles', DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info