-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
138 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export class Hibernation1696331570827 { | ||
name = 'Hibernation1696331570827' | ||
|
||
async up(queryRunner) { | ||
await queryRunner.query(`DROP INDEX "public"."IDX_d74d8ab5efa7e3bb82825c0fa2"`); | ||
await queryRunner.query(`ALTER TABLE "user" ADD "isHibernated" boolean NOT NULL DEFAULT false`); | ||
await queryRunner.query(`ALTER TABLE "following" ADD "isFollowerHibernated" boolean NOT NULL DEFAULT false`); | ||
await queryRunner.query(`CREATE INDEX "IDX_ce62b50d882d4e9dee10ad0d2f" ON "following" ("followeeId", "followerHost", "isFollowerHibernated") `); | ||
} | ||
|
||
async down(queryRunner) { | ||
await queryRunner.query(`DROP INDEX "public"."IDX_ce62b50d882d4e9dee10ad0d2f"`); | ||
await queryRunner.query(`ALTER TABLE "following" DROP COLUMN "isFollowerHibernated"`); | ||
await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "isHibernated"`); | ||
await queryRunner.query(`CREATE INDEX "IDX_d74d8ab5efa7e3bb82825c0fa2" ON "following" ("followeeId", "followerHost") `); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and other misskey contributors | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import { Inject, Injectable } from '@nestjs/common'; | ||
import type { FollowingsRepository, UsersRepository } from '@/models/_.js'; | ||
import type { MiUser } from '@/models/User.js'; | ||
import { DI } from '@/di-symbols.js'; | ||
import { bindThis } from '@/decorators.js'; | ||
|
||
@Injectable() | ||
export class UserService { | ||
constructor( | ||
@Inject(DI.usersRepository) | ||
private usersRepository: UsersRepository, | ||
|
||
@Inject(DI.followingsRepository) | ||
private followingsRepository: FollowingsRepository, | ||
) { | ||
} | ||
|
||
@bindThis | ||
public async updateLastActiveDate(user: MiUser): Promise<void> { | ||
if (user.isHibernated) { | ||
const result = await this.usersRepository.createQueryBuilder().update() | ||
.set({ | ||
lastActiveDate: new Date(), | ||
}) | ||
.where('id = :id', { id: user.id }) | ||
.returning('*') | ||
.execute() | ||
.then((response) => { | ||
return response.raw[0]; | ||
}); | ||
const wokeUp = result.isHibernated; | ||
if (wokeUp) { | ||
this.usersRepository.update(user.id, { | ||
isHibernated: false, | ||
}); | ||
this.followingsRepository.update({ | ||
followerId: user.id, | ||
}, { | ||
isFollowerHibernated: false, | ||
}); | ||
} | ||
} else { | ||
this.usersRepository.update(user.id, { | ||
lastActiveDate: new Date(), | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters