Skip to content

Commit

Permalink
feat: 캐시 확인을 함수에서 하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoto-Cocoa committed Jul 13, 2023
1 parent d3cc733 commit 88af272
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ function isFileShouldNotIncluded(file: Misskey.entities.DriveFile, user: User):
}

async function sendErrorNotification(username: string, host: string, message: string): Promise<void> {
const targetUserId = await redisClient.get(`hotomoe-crossposter-worker:user-id:${username}@${host}`) ?? await getMisskeyUserId(host, username);
const adminUserId = await redisClient.get(`hotomoe-crossposter-worker:user-id:${process.env.MISSKEY_ADMIN}@${process.env.MISSKEY_INSTANCE}`) ?? await getMisskeyUserId(process.env.MISSKEY_INSTANCE, process.env.MISSKEY_ADMIN);
const targetUserId = await getMisskeyUserId(host, username);
const adminUserId = await getMisskeyUserId(process.env.MISSKEY_INSTANCE, process.env.MISSKEY_ADMIN);

await axios.post(`https://${process.env.MISSKEY_INSTANCE}/api/notes/create`, JSON.stringify({
visibility: 'specified',
Expand All @@ -484,6 +484,12 @@ async function sendErrorNotification(username: string, host: string, message: st
}

async function getMisskeyUserId(host: string, username: string): Promise<string> {
const cachedId = await redisClient.get(`hotomoe-crossposter-worker:user-id:${username}@${host}`);

if (cachedId) {
return cachedId;
}

const response = await axios.post(`https://${process.env.MISSKEY_INSTANCE}/api/users/show`, JSON.stringify({
username,
host,
Expand Down

0 comments on commit 88af272

Please sign in to comment.