Skip to content

Commit

Permalink
Repostされてからの時間判定を投稿時間と比較するよう修正
Browse files Browse the repository at this point in the history
  • Loading branch information
dolciss committed Aug 31, 2024
1 parent eebe573 commit 51244c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/db/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,13 @@ migrations['003'] = {
await db.schema.alterTable('repost').dropColumn('createdAt').execute()
},
}
migrations['004'] = {
async up(db: Kysely<unknown>) {
await db.schema.alterTable('post')
.addColumn('createdAt', 'varchar')
.execute()
},
async down(db: Kysely<unknown>) {
await db.schema.alterTable('post').dropColumn('createdAt').execute()
},
}
7 changes: 5 additions & 2 deletions src/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
prevOriginalUri: authorReposts.get(create.author)?.originalUri ?? null,
replyParent: create.record?.reply?.parent.uri ?? null,
replyRoot: create.record?.reply?.root.uri ?? null,
createdAt: create.record.createdAt,
indexedAt: new Date().toISOString(),
}
})
Expand All @@ -126,7 +127,8 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
continue
}
const isNotReply = (post.record?.reply?.parent.uri ?? null) == null
const repostDelayTime = nowTime - Date.parse(authorReposts.get(post.author)?.createdAt ?? nowTime.toString())
const repostDelayTime = Date.parse(post.record.createdAt ?? nowTime.toString())
- Date.parse(authorReposts.get(post.author)?.createdAt ?? nowTime.toString())
console.log('[Post]', authorReposts.get(post.author)?.originalDid ?? 'none', '\'s NextPost by', post.author
, isNotReply ? 'is Post' : 'is Reply'
, 'delay:' + repostDelayTime + 'ms'
Expand All @@ -137,7 +139,8 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
if (postsToCreate.length > 0) {
// DBに登録するのはReplyがなく、1時間以内のものだけ
const insertPost = postsToCreate.filter((create) => {
const repostDelayTime = nowTime - Date.parse(authorReposts.get(create.author)?.createdAt ?? nowTime.toString())
const repostDelayTime = Date.parse(create.createdAt ?? nowTime.toString())
- Date.parse(authorReposts.get(create.author)?.createdAt ?? nowTime.toString())
return create.replyParent == null && repostDelayTime < 60 * 60 * 1000
})
if (insertPost.length > 0) {
Expand Down

0 comments on commit 51244c5

Please sign in to comment.