diff --git a/app/repositories/globalbrain.ts b/app/repositories/globalbrain.ts index 4bf1fef4..23ad736f 100644 --- a/app/repositories/globalbrain.ts +++ b/app/repositories/globalbrain.ts @@ -65,14 +65,6 @@ export async function processScoreEvents( }), ) - // Ideally, we would update this table incrementally, but for now we just - // delete all rows and reinsert them. - await sql`delete from CriticalThread`.execute(trx) - await sql` - insert into CriticalThread - select * from CriticalThreadView - `.execute(trx) - if (!gotExpectedScoreEvent) { console.error( `Expected score event not found: ${voteEvent.voteEventId}, ${voteEvent.postId}`, diff --git a/app/repositories/ranking.ts b/app/repositories/ranking.ts index 6352c2d6..63124499 100644 --- a/app/repositories/ranking.ts +++ b/app/repositories/ranking.ts @@ -62,7 +62,6 @@ export async function getCommentTreeState( 'FullScore.p as p', 'FullScore.oSize as voteCount', 'Post.deletedAt as deletedAt', - 'FullScore.criticalThreadId', ]) .where('Post.id', 'in', descendantIds.concat([targetPostId])) .where('p', 'is not', null) @@ -72,29 +71,14 @@ export async function getCommentTreeState( ? await getUserVotes(trx, userId, descendantIds.concat([targetPostId])) : undefined - const criticalCommentIdToTargetId: { [key: number]: number[] } = {} - results.forEach(res => { - const criticalThreadId = res.criticalThreadId - if (criticalThreadId !== null) { - const entry = criticalCommentIdToTargetId[criticalThreadId] - if (entry !== undefined) { - entry.push(res.postId) - } else { - criticalCommentIdToTargetId[criticalThreadId] = [res.postId] - } - } - }) - let commentTreeState: CommentTreeState = { targetPostId, - criticalCommentIdToTargetId, posts: {}, } await Promise.all( results.map(async result => { commentTreeState.posts[result.postId] = { - criticalCommentId: result.criticalThreadId, // We have to use the non-null assertion here because kysely doesn't // return values as non-null type even if we filter nulls with a where // condition. We can, however, be sure that the values are never null. diff --git a/app/repositories/vote.ts b/app/repositories/vote.ts index 6aaf1b00..075fbf94 100644 --- a/app/repositories/vote.ts +++ b/app/repositories/vote.ts @@ -104,7 +104,7 @@ export async function getUserVotes( .where(eb => eb('id', 'in', postIds)) .leftJoin('Vote as VoteOnCriticalReply', join => join - .onRef('VoteOnCriticalReply.postId', '=', 'criticalThreadId') + .onRef('VoteOnCriticalReply.postId', '=', 'criticalThreadId') // TODO: what to do here? .onRef('VoteOnCriticalReply.userId', '=', 'Vote.userId'), ) .select('Post.id as postId') diff --git a/app/routes/stats.$postId.tsx b/app/routes/stats.$postId.tsx index dc7aa990..22da77ac 100644 --- a/app/routes/stats.$postId.tsx +++ b/app/routes/stats.$postId.tsx @@ -68,26 +68,6 @@ export default function PostStats() { } ▼   **o**: ${(post.o * 100).toFixed(1)}% - **p:** ${(post.p * 100).toFixed(1)}% - **score:** ${post.score} -` - - const topCommentMarkdown = - post.criticalThreadId == null - ? '' - : ` -## Critical Comment - -- **top reply id:** ${ - post.criticalThreadId == null - ? 'null' - : `[${post.criticalThreadId}](/stats/${post.criticalThreadId})` - } -- **informed votes:**      ${post.pCount} ▲ ${ - post.pSize - post.pCount - } ▼   **p**: ${(post.p * 100).toFixed(1)}% -- **uninformed votes:** ${post.qCount} ▲ ${ - post.qSize - post.qCount - } ▼   **q**: ${(post.q * 100).toFixed(1)}% -- **r**: ${post.r.toFixed(3)} ` // - q = Bayesian Average(upvotes/votes), upvoteProbabilityPrior) @@ -135,7 +115,7 @@ ${effects return (
- {overallMarkdown + topCommentMarkdown + effectsMarkdown} + {overallMarkdown + effectsMarkdown}
) diff --git a/app/types/api-types.ts b/app/types/api-types.ts index f4371455..0b03e6a3 100644 --- a/app/types/api-types.ts +++ b/app/types/api-types.ts @@ -47,7 +47,6 @@ export type ImmutableReplyTree = { } export type PostState = { - criticalCommentId: number | null voteState: VoteState voteCount: number p: number | null @@ -57,9 +56,6 @@ export type PostState = { export type CommentTreeState = { targetPostId: number - criticalCommentIdToTargetId: { - [key: number]: number[] - } posts: { [key: number]: PostState } @@ -101,6 +97,4 @@ export type StatsPost = Post & { qSize: number r: number weight: number - - criticalThreadId: number | null } diff --git a/app/types/kysely-types.ts b/app/types/kysely-types.ts index 7cf35a4f..6f498182 100644 --- a/app/types/kysely-types.ts +++ b/app/types/kysely-types.ts @@ -120,10 +120,7 @@ export type EffectEvent = Effect & { voteEventTime: number } -export type FullScore = Score & - Effect & { - criticalThreadId: number | null - } +export type FullScore = Score & Effect export type Lineage = { ancestorId: number diff --git a/migrations/2024-07-05-remove-critical-thread-table.ts b/migrations/2024-07-05-remove-critical-thread-table.ts new file mode 100644 index 00000000..ab2f35cc --- /dev/null +++ b/migrations/2024-07-05-remove-critical-thread-table.ts @@ -0,0 +1,8 @@ +import { type Kysely, sql } from 'kysely' + +export async function up(db: Kysely): Promise { + await db.transaction().execute(async trx => { + await sql`drop view CriticalThreadView`.execute(trx) + await sql`drop table CriticalThread`.execute(trx) + }) +}