See the best posts from any Bluesky account
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Clamp negative engagement counts from AppView API to zero

The Bluesky API occasionally returns negative quoteCount (and potentially
likeCount/repostCount) on some posts, which ClickHouse rejects on insert
because the snapshot columns are UInt32.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+24 -3
+3 -3
app/lib/atproto/parsers/get_author_feed.ts
··· 210 210 const postText = getString(record, 'text') 211 211 const createdAtStr = getString(record, 'createdAt') 212 212 213 - const snapshotLikes = getNumber(post, 'likeCount', 0) 214 - const snapshotReposts = getNumber(post, 'repostCount', 0) 215 - const snapshotQuotes = getNumber(post, 'quoteCount', 0) 213 + const snapshotLikes = Math.max(0, getNumber(post, 'likeCount', 0)) 214 + const snapshotReposts = Math.max(0, getNumber(post, 'repostCount', 0)) 215 + const snapshotQuotes = Math.max(0, getNumber(post, 'quoteCount', 0)) 216 216 217 217 const parsedEmbed = parsePostEmbed(post['embed'], postUri) 218 218 if (parsedEmbed === SKIP_QUOTE) {
+21
tests/unit/atproto/get_author_feed.spec.ts
··· 240 240 assert.equal(result[0].snapshotQuotes, 0) 241 241 }) 242 242 243 + test('clamps negative engagement counts to 0', ({ assert }) => { 244 + const response = { 245 + feed: [ 246 + makeFeedItem( 247 + makePostView({ 248 + uri: `at://${TARGET_DID}/app.bsky.feed.post/negcounts`, 249 + likeCount: -1, 250 + repostCount: -5, 251 + quoteCount: -3, 252 + }) 253 + ), 254 + ], 255 + } 256 + 257 + const result = parseGetAuthorFeedResponse(response, TARGET_DID) 258 + assert.equal(result.length, 1) 259 + assert.equal(result[0].snapshotLikes, 0) 260 + assert.equal(result[0].snapshotReposts, 0) 261 + assert.equal(result[0].snapshotQuotes, 0) 262 + }) 263 + 243 264 test('throws when feed field is not an array', ({ assert }) => { 244 265 assert.throws(() => parseGetAuthorFeedResponse({ feed: 'not an array' }, TARGET_DID)) 245 266 assert.throws(() => parseGetAuthorFeedResponse({}, TARGET_DID))