-
Notifications
You must be signed in to change notification settings - Fork 574
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix up mock dataplane to match new protos
- Loading branch information
Showing
13 changed files
with
254 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,33 @@ | ||
import { ServiceImpl } from '@connectrpc/connect' | ||
import { Service } from '../../gen/bsky_connect' | ||
import { keyBy } from '@atproto/common' | ||
import * as ui8 from 'uint8arrays' | ||
import { Database } from '../../../db' | ||
|
||
export default (db: Database): Partial<ServiceImpl<typeof Service>> => ({ | ||
async getPosts(req) { | ||
async getPostReplyCounts(req) { | ||
if (req.uris.length === 0) { | ||
return { records: [] } | ||
return { counts: [] } | ||
} | ||
const res = await db.db | ||
.selectFrom('record') | ||
.selectAll() | ||
.selectFrom('post_agg') | ||
.select(['uri', 'replyCount']) | ||
.where('uri', 'in', req.uris) | ||
.execute() | ||
const byUri = keyBy(res, 'uri') | ||
const records = req.uris.map((uri) => { | ||
const row = byUri[uri] | ||
const json = row ? row.json : JSON.stringify(null) | ||
return ui8.fromString(json, 'utf8') | ||
}) | ||
return { records } | ||
const counts = req.uris.map((uri) => byUri[uri]?.replyCount ?? 0) | ||
return { counts } | ||
}, | ||
async getPostReplyCount(req) { | ||
if (req.uris.length === 0) { | ||
async getPostCounts(req) { | ||
if (req.dids.length === 0) { | ||
return { counts: [] } | ||
} | ||
const res = await db.db | ||
.selectFrom('post_agg') | ||
.select(['uri', 'replyCount']) | ||
.where('uri', 'in', req.uris) | ||
.selectFrom('profile_agg') | ||
.selectAll() | ||
.where('did', 'in', req.dids) | ||
.execute() | ||
const byUri = keyBy(res, 'uri') | ||
const counts = req.uris.map((uri) => byUri[uri]?.replyCount ?? 0) | ||
const byDid = keyBy(res, 'did') | ||
const counts = req.dids.map((did) => byDid[did]?.postsCount ?? 0) | ||
return { counts } | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.