MCPcopy Index your code
hub / github.com/AnswerOverflow/AnswerOverflow / listPublicThreads

Function listPublicThreads

packages/core/src/sitemap.ts:14–64  ·  view source on GitHub ↗
(opts: {
	offset: number;
	limit?: number;
})

Source from the content-addressed store, hash-verified

12import { findManyServersById } from './server';
13import { JSONParse, JSONStringify } from './utils/json-big';
14export async function listPublicThreads(opts: {
15 offset: number;
16 limit?: number;
17}) {
18 const { limit = 50000 } = opts;
19
20 let start = Date.now();
21 const threads = await dbReplica.query.dbChannels.findMany({
22 where: eq(dbChannels.type, ChannelType.PublicThread),
23 offset: limit * opts.offset,
24 limit: limit,
25 });
26 let end = Date.now();
27 console.log(`findAllThreadsForSitemap took ${end - start}ms`);
28
29 const parents = await findManyChannelsById(
30 threads.filter((t) => t.parentId !== null).map((t) => t.parentId!),
31 );
32 const parentLookup = new Map(parents.map((p) => [p.id, p]));
33 const filterThreads = threads.filter(
34 (t) => parentLookup.get(t.parentId ?? '')?.flags.indexingEnabled,
35 );
36
37 const questionIds = filterThreads.map((c) => c.id);
38
39 start = Date.now();
40 const questions =
41 questionIds.length > 0
42 ? await findManyMessagesWithAuthors(questionIds, {
43 excludePrivateMessages: true,
44 })
45 : [];
46 const questionLookup = new Map(questions.map((q) => [q.id, q]));
47
48 const servers = await findManyServersById(
49 filterThreads.map((c) => c.serverId),
50 );
51 const serverLookup = new Map(servers.map((s) => [s.id, s]));
52 end = Date.now();
53 console.log(`findAllThreadsForSitemap messages took ${end - start}ms`);
54
55 return {
56 threads: filterThreads.filter(
57 (t) =>
58 questionLookup.has(t.id) &&
59 !serverLookup.get(t.serverId)?.customDomain &&
60 !serverLookup.get(t.serverId)?.kickedTime,
61 ),
62 hasMore: threads.length === limit,
63 };
64}
65
66// todo: deduplicate
67type Snowflake = string;

Callers 1

generateSitemapFunction · 0.85

Calls 3

findManyChannelsByIdFunction · 0.90
findManyServersByIdFunction · 0.90

Tested by

no test coverage detected