Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions app/repositories/globalbrain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
16 changes: 0 additions & 16 deletions app/repositories/ranking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion app/repositories/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
22 changes: 1 addition & 21 deletions app/routes/stats.$postId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -135,7 +115,7 @@ ${effects
return (
<div className="markdown">
<Markdown deactivateLinks={false}>
{overallMarkdown + topCommentMarkdown + effectsMarkdown}
{overallMarkdown + effectsMarkdown}
</Markdown>
</div>
)
Expand Down
6 changes: 0 additions & 6 deletions app/types/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export type ImmutableReplyTree = {
}

export type PostState = {
criticalCommentId: number | null
voteState: VoteState
voteCount: number
p: number | null
Expand All @@ -57,9 +56,6 @@ export type PostState = {

export type CommentTreeState = {
targetPostId: number
criticalCommentIdToTargetId: {
[key: number]: number[]
}
posts: {
[key: number]: PostState
}
Expand Down Expand Up @@ -101,6 +97,4 @@ export type StatsPost = Post & {
qSize: number
r: number
weight: number

criticalThreadId: number | null
}
5 changes: 1 addition & 4 deletions app/types/kysely-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions migrations/2024-07-05-remove-critical-thread-table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { type Kysely, sql } from 'kysely'

export async function up(db: Kysely<any>): Promise<void> {
await db.transaction().execute(async trx => {
await sql`drop view CriticalThreadView`.execute(trx)
await sql`drop table CriticalThread`.execute(trx)
})
}