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

Function upsertManyMessages

packages/core/src/message-node.ts:120–167  ·  view source on GitHub ↗
(
	data: BaseMessageWithRelations[],
	opts?: {
		ignoreChecks?: boolean;
	},
)

Source from the content-addressed store, hash-verified

118}
119
120export async function upsertManyMessages(
121 data: BaseMessageWithRelations[],
122 opts?: {
123 ignoreChecks?: boolean;
124 },
125) {
126 if (data.length === 0) return Promise.resolve([]);
127 const authorIds = new Set(data.map((msg) => msg.authorId));
128
129 // Todo: make one query for all of these
130 if (!opts?.ignoreChecks) {
131 const [ignoredAccounts, userServerSettings] = await Promise.all([
132 findManyIgnoredDiscordAccountsById(Array.from(authorIds)),
133 findManyUserServerSettings(
134 data.map((msg) => ({
135 userId: msg.authorId,
136 serverId: msg.serverId,
137 })),
138 ),
139 ]);
140 const userServerSettingsLookup = new Map(
141 userServerSettings.map((uss) => [`${uss.userId}-${uss.serverId}`, uss]),
142 );
143
144 const ignoredAccountIds = new Set(ignoredAccounts.map((i) => i.id));
145 data = data.filter((msg) => {
146 if (ignoredAccountIds.has(msg.authorId)) {
147 return false;
148 }
149 if (
150 userServerSettingsLookup.get(`${msg.authorId}-${msg.serverId}`)?.flags
151 .messageIndexingDisabled
152 ) {
153 return false;
154 }
155 return true;
156 });
157 }
158 const chunkSize = 100;
159 const chunks = [];
160 for (let i = 0; i < data.length; i += chunkSize) {
161 chunks.push(data.slice(i, i + chunkSize));
162 }
163 for await (const chunk of chunks) {
164 await fastUpsertManyMessages(chunk);
165 }
166 return data;
167}
168
169export async function fastUpsertManyMessages(data: BaseMessageWithRelations[]) {
170 const attachments = new Set<typeof dbAttachments.$inferInsert>();

Callers 3

seedOneFunction · 0.90
seedTwoFunction · 0.90
storeIndexDataFunction · 0.90

Calls 3

fastUpsertManyMessagesFunction · 0.85

Tested by

no test coverage detected