Adjust decay formula (#7535)
This commit is contained in:
@@ -53,8 +53,9 @@ export type ThreadPost = {
|
|||||||
uri: string
|
uri: string
|
||||||
post: AppBskyFeedDefs.PostView
|
post: AppBskyFeedDefs.PostView
|
||||||
record: AppBskyFeedPost.Record
|
record: AppBskyFeedPost.Record
|
||||||
parent?: ThreadNode
|
parent: ThreadNode | undefined
|
||||||
replies?: ThreadNode[]
|
replies: ThreadNode[] | undefined
|
||||||
|
hasOPLike: boolean | undefined
|
||||||
ctx: ThreadCtx
|
ctx: ThreadCtx
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,8 +256,8 @@ export function sortThread(
|
|||||||
if (aFetchedAt !== bFetchedAt) {
|
if (aFetchedAt !== bFetchedAt) {
|
||||||
return aFetchedAt - bFetchedAt // older fetches first
|
return aFetchedAt - bFetchedAt // older fetches first
|
||||||
} else if (opts.sort === 'hotness') {
|
} else if (opts.sort === 'hotness') {
|
||||||
const aHotness = getHotness(a.post, aFetchedAt)
|
const aHotness = getHotness(a, aFetchedAt)
|
||||||
const bHotness = getHotness(b.post, bFetchedAt /* same as aFetchedAt */)
|
const bHotness = getHotness(b, bFetchedAt /* same as aFetchedAt */)
|
||||||
return bHotness - aHotness
|
return bHotness - aHotness
|
||||||
} else if (opts.sort === 'oldest') {
|
} else if (opts.sort === 'oldest') {
|
||||||
return a.post.indexedAt.localeCompare(b.post.indexedAt)
|
return a.post.indexedAt.localeCompare(b.post.indexedAt)
|
||||||
@@ -309,7 +310,8 @@ export function sortThread(
|
|||||||
// We want to give recent comments a real chance (and not bury them deep below the fold)
|
// We want to give recent comments a real chance (and not bury them deep below the fold)
|
||||||
// while also surfacing well-liked comments from the past. In the future, we can explore
|
// while also surfacing well-liked comments from the past. In the future, we can explore
|
||||||
// something more sophisticated, but we don't have much data on the client right now.
|
// something more sophisticated, but we don't have much data on the client right now.
|
||||||
function getHotness(post: AppBskyFeedDefs.PostView, fetchedAt: number) {
|
function getHotness(threadPost: ThreadPost, fetchedAt: number) {
|
||||||
|
const {post, hasOPLike} = threadPost
|
||||||
const hoursAgo = Math.max(
|
const hoursAgo = Math.max(
|
||||||
0,
|
0,
|
||||||
(new Date(fetchedAt).getTime() - new Date(post.indexedAt).getTime()) /
|
(new Date(fetchedAt).getTime() - new Date(post.indexedAt).getTime()) /
|
||||||
@@ -318,7 +320,8 @@ function getHotness(post: AppBskyFeedDefs.PostView, fetchedAt: number) {
|
|||||||
const likeCount = post.likeCount ?? 0
|
const likeCount = post.likeCount ?? 0
|
||||||
const likeOrder = Math.log(3 + likeCount)
|
const likeOrder = Math.log(3 + likeCount)
|
||||||
const timePenaltyExponent = 1.5 + 1.5 / (1 + Math.log(1 + likeCount))
|
const timePenaltyExponent = 1.5 + 1.5 / (1 + Math.log(1 + likeCount))
|
||||||
const timePenalty = Math.pow(hoursAgo + 2, timePenaltyExponent)
|
const opLikeBoost = hasOPLike ? 0.85 : 1.0
|
||||||
|
const timePenalty = Math.pow(hoursAgo + 2, timePenaltyExponent * opLikeBoost)
|
||||||
return likeOrder / timePenalty
|
return likeOrder / timePenalty
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,6 +359,8 @@ function responseToThreadNodes(
|
|||||||
// do not show blocked posts in replies
|
// do not show blocked posts in replies
|
||||||
.filter(node => node.type !== 'blocked')
|
.filter(node => node.type !== 'blocked')
|
||||||
: undefined,
|
: undefined,
|
||||||
|
// @ts-ignore TODO: Update API package.
|
||||||
|
hasOPLike: Boolean(node?.threadContext?.rootAuthorLike),
|
||||||
ctx: {
|
ctx: {
|
||||||
depth,
|
depth,
|
||||||
isHighlightedPost: depth === 0,
|
isHighlightedPost: depth === 0,
|
||||||
@@ -552,6 +557,7 @@ function threadNodeToPlaceholderThread(
|
|||||||
record: node.record,
|
record: node.record,
|
||||||
parent: undefined,
|
parent: undefined,
|
||||||
replies: undefined,
|
replies: undefined,
|
||||||
|
hasOPLike: undefined,
|
||||||
ctx: {
|
ctx: {
|
||||||
depth: 0,
|
depth: 0,
|
||||||
isHighlightedPost: true,
|
isHighlightedPost: true,
|
||||||
@@ -573,6 +579,7 @@ function postViewToPlaceholderThread(
|
|||||||
record: post.record as AppBskyFeedPost.Record, // validated in notifs
|
record: post.record as AppBskyFeedPost.Record, // validated in notifs
|
||||||
parent: undefined,
|
parent: undefined,
|
||||||
replies: undefined,
|
replies: undefined,
|
||||||
|
hasOPLike: undefined,
|
||||||
ctx: {
|
ctx: {
|
||||||
depth: 0,
|
depth: 0,
|
||||||
isHighlightedPost: true,
|
isHighlightedPost: true,
|
||||||
@@ -594,6 +601,7 @@ function embedViewRecordToPlaceholderThread(
|
|||||||
record: record.value as AppBskyFeedPost.Record, // validated in getEmbeddedPost
|
record: record.value as AppBskyFeedPost.Record, // validated in getEmbeddedPost
|
||||||
parent: undefined,
|
parent: undefined,
|
||||||
replies: undefined,
|
replies: undefined,
|
||||||
|
hasOPLike: undefined,
|
||||||
ctx: {
|
ctx: {
|
||||||
depth: 0,
|
depth: 0,
|
||||||
isHighlightedPost: true,
|
isHighlightedPost: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user