Skip to content

Commit

Permalink
전체 입실여부 조회 함수 중 db조회 방법에 따른 속도 비교
Browse files Browse the repository at this point in the history
  • Loading branch information
niamu01 committed Jul 3, 2024
1 parent 88c05f5 commit 44bc813
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/external/where42/where42.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,10 @@ export class Where42Controller {
this.logger.debug(`@where42All) where42All`);
return this.where42Service.where42All(logins);
}

@Post('where42All2')
async where42All2(@Body() logins: string[]): Promise<Where42ResponseDto[]> {
this.logger.debug(`@where42All) where42All`);
return this.where42Service.where42All2(logins);
}
}
63 changes: 63 additions & 0 deletions src/external/where42/where42.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Post,
} from '@nestjs/common';
import { ITagLogRepository } from 'src/tag-log/repository/interface/tag-log-repository.interface';
import { IdLoginDto } from 'src/user/dto/id-login.dto';
import { UserService } from 'src/user/user.service';
import { Where42ResponseDto } from './dto/where42.response.dto';
import { IDeviceInfoRepository } from './repository/interface/device-info.repository.interface';
Expand Down Expand Up @@ -72,4 +73,66 @@ export class Where42Service {
}
return res;
}

@Post('where42All2')
async where42All2(@Body() logins: string[]): Promise<Where42ResponseDto[]> {
const users = await this.userService.findUsersByLogins(logins);
const userMap = new Map<string, IdLoginDto>(
users.map((user) => [user.login, user]),
);

const res = [];

for (const login of logins) {
try {
const user = userMap.get(login);
if (!user) {
throw new BadRequestException('존재하지 않는 유저 ID입니다.');
}

const isAdmin = user.is_admin;

if (isAdmin) {
res.push({
login,
inoutState: null,
});
continue;
}

const cards = await this.userService.findCardsByUserId(
user.user_id,
new Date('2019-01-01 00:00:00'),
new Date(), // NOTE: 대략 42 클러스터 오픈일부터 지금까지 조회
);

const last = await this.tagLogRepository.findLatestTagLog(cards);
if (last === null) {
throw new ForbiddenException('태그 기록이 존재하지 않습니다.');
}

const device = await this.deviceInfoRepository.getDeviceInfo(
last.device_id,
);
if (device === null) {
throw new ForbiddenException(
'등록되지 않은 기기에 태그하였습니다. 관리자에게 문의하세요.',
);
}

res.push({
login,
inoutState: device.inoutState,
});
} catch (e) {
this.logger.error(`정상적인 조회가 아님: ${login}`);
res.push({
login,
inoutState: null,
});
}
}

return res;
}
}

0 comments on commit 44bc813

Please sign in to comment.