summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/RoleService.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-10-16 10:45:22 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-10-16 10:45:22 +0900
commit1fa1d316969de15d6aaef1dbf0a0b95aec30e377 (patch)
treebacefb9f8dbc2cc18d8c775cdd0572263b4e11ef /packages/backend/src/core/RoleService.ts
parentUpdate CHANGELOG.md (diff)
downloadsharkey-1fa1d316969de15d6aaef1dbf0a0b95aec30e377.tar.gz
sharkey-1fa1d316969de15d6aaef1dbf0a0b95aec30e377.tar.bz2
sharkey-1fa1d316969de15d6aaef1dbf0a0b95aec30e377.zip
perf(backend): createdAtをidから取得するように & 無駄なDateインスタンスの生成を避けるように
Diffstat (limited to 'packages/backend/src/core/RoleService.ts')
-rw-r--r--packages/backend/src/core/RoleService.ts17
1 files changed, 6 insertions, 11 deletions
diff --git a/packages/backend/src/core/RoleService.ts b/packages/backend/src/core/RoleService.ts
index 2c3547e4ac..d18fb240f7 100644
--- a/packages/backend/src/core/RoleService.ts
+++ b/packages/backend/src/core/RoleService.ts
@@ -125,7 +125,6 @@ export class RoleService implements OnApplicationShutdown {
if (cached) {
cached.push({
...body,
- createdAt: new Date(body.createdAt),
updatedAt: new Date(body.updatedAt),
lastUsedAt: new Date(body.lastUsedAt),
});
@@ -139,7 +138,6 @@ export class RoleService implements OnApplicationShutdown {
if (i > -1) {
cached[i] = {
...body,
- createdAt: new Date(body.createdAt),
updatedAt: new Date(body.updatedAt),
lastUsedAt: new Date(body.lastUsedAt),
};
@@ -159,7 +157,6 @@ export class RoleService implements OnApplicationShutdown {
if (cached) {
cached.push({
...body,
- createdAt: new Date(body.createdAt),
expiresAt: body.expiresAt ? new Date(body.expiresAt) : null,
});
}
@@ -198,10 +195,10 @@ export class RoleService implements OnApplicationShutdown {
return this.userEntityService.isRemoteUser(user);
}
case 'createdLessThan': {
- return user.createdAt.getTime() > (Date.now() - (value.sec * 1000));
+ return this.idService.parse(user.id).date.getTime() > (Date.now() - (value.sec * 1000));
}
case 'createdMoreThan': {
- return user.createdAt.getTime() < (Date.now() - (value.sec * 1000));
+ return this.idService.parse(user.id).date.getTime() < (Date.now() - (value.sec * 1000));
}
case 'followersLessThanOrEq': {
return user.followersCount <= value.value;
@@ -382,7 +379,7 @@ export class RoleService implements OnApplicationShutdown {
@bindThis
public async assign(userId: MiUser['id'], roleId: MiRole['id'], expiresAt: Date | null = null, moderator?: MiUser): Promise<void> {
- const now = new Date();
+ const now = Date.now();
const role = await this.rolesRepository.findOneByOrFail({ id: roleId });
@@ -392,7 +389,7 @@ export class RoleService implements OnApplicationShutdown {
});
if (existing) {
- if (existing.expiresAt && (existing.expiresAt.getTime() < now.getTime())) {
+ if (existing.expiresAt && (existing.expiresAt.getTime() < now)) {
await this.roleAssignmentsRepository.delete({
roleId: roleId,
userId: userId,
@@ -403,8 +400,7 @@ export class RoleService implements OnApplicationShutdown {
}
const created = await this.roleAssignmentsRepository.insert({
- id: this.idService.genId(),
- createdAt: now,
+ id: this.idService.gen(now),
expiresAt: expiresAt,
roleId: roleId,
userId: userId,
@@ -485,8 +481,7 @@ export class RoleService implements OnApplicationShutdown {
public async create(values: Partial<MiRole>, moderator?: MiUser): Promise<MiRole> {
const date = new Date();
const created = await this.rolesRepository.insert({
- id: this.idService.genId(),
- createdAt: date,
+ id: this.idService.gen(date.getTime()),
updatedAt: date,
lastUsedAt: date,
name: values.name,