refactor
This commit is contained in:
parent
dab205edb8
commit
132b01461d
|
@ -9,6 +9,8 @@ import type { MiNote } from '@/models/_.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
|
|
||||||
|
const GLOBAL_NOTES_RANKING_WINDOW = 1000 * 60 * 60 * 24 * 3; // 3日ごと
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FeaturedService {
|
export class FeaturedService {
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -26,7 +28,7 @@ export class FeaturedService {
|
||||||
@bindThis
|
@bindThis
|
||||||
private getCurrentGlobalNotesRankingWindow(): number {
|
private getCurrentGlobalNotesRankingWindow(): number {
|
||||||
const passed = new Date().getTime() - new Date(new Date().getFullYear(), 0, 1).getTime();
|
const passed = new Date().getTime() - new Date(new Date().getFullYear(), 0, 1).getTime();
|
||||||
return Math.floor(passed / (1000 * 60 * 60 * 24 * 3)); // 3日ごと
|
return Math.floor(passed / GLOBAL_NOTES_RANKING_WINDOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
@ -40,7 +42,7 @@ export class FeaturedService {
|
||||||
noteId);
|
noteId);
|
||||||
redisTransaction.expire(
|
redisTransaction.expire(
|
||||||
`featuredGlobalNotesRanking:${currentWindow}`,
|
`featuredGlobalNotesRanking:${currentWindow}`,
|
||||||
60 * 60 * 24 * 9, // 9日間保持
|
(GLOBAL_NOTES_RANKING_WINDOW * 3) / 1000,
|
||||||
'NX'); // "NX -- Set expiry only when the key has no expiry" = 有効期限がないときだけ設定
|
'NX'); // "NX -- Set expiry only when the key has no expiry" = 有効期限がないときだけ設定
|
||||||
await redisTransaction.exec();
|
await redisTransaction.exec();
|
||||||
}
|
}
|
||||||
|
@ -55,7 +57,7 @@ export class FeaturedService {
|
||||||
noteId);
|
noteId);
|
||||||
redisTransaction.expire(
|
redisTransaction.expire(
|
||||||
`featuredInChannelNotesRanking:${channelId}:${currentWindow}`,
|
`featuredInChannelNotesRanking:${channelId}:${currentWindow}`,
|
||||||
60 * 60 * 24 * 9, // 9日間保持
|
(GLOBAL_NOTES_RANKING_WINDOW * 3) / 1000,
|
||||||
'NX'); // "NX -- Set expiry only when the key has no expiry" = 有効期限がないときだけ設定
|
'NX'); // "NX -- Set expiry only when the key has no expiry" = 有効期限がないときだけ設定
|
||||||
await redisTransaction.exec();
|
await redisTransaction.exec();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue