MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / saveAllThreads

Function saveAllThreads

apps/web/services/slack/sync/saveAllThreads.ts:104–195  ·  view source on GitHub ↗
({
  channel,
  token,
  usersInDb,
  fetchReplies,
  logger,
}: {
  channel: channels;
  token: string;
  usersInDb: UserMap[];
  fetchReplies: Function;
  logger: Logger;
})

Source from the content-addressed store, hash-verified

102}
103
104export async function saveAllThreads({
105 channel,
106 token,
107 usersInDb,
108 fetchReplies,
109 logger,
110}: {
111 channel: channels;
112 token: string;
113 usersInDb: UserMap[];
114 fetchReplies: Function;
115 logger: Logger;
116}) {
117 const channelName = channel.channelName;
118
119 let cursor = 0;
120 if (channel.externalPageCursor) {
121 if (channel.externalPageCursor === 'completed') {
122 logger.log({
123 channelName,
124 syncing: 'skipped. externalPageCursor=completed',
125 });
126 return;
127 }
128 try {
129 let { threadCursor } = JSON.parse(channel.externalPageCursor);
130 if (threadCursor && !isNaN(threadCursor)) {
131 cursor = threadCursor;
132 }
133 } catch (error) {}
134 }
135
136 logger.log({ channelName, 'syncingAllThreads startedAt': new Date() });
137 const tooManyRequests = [];
138
139 do {
140 logger.log({ channelName, cursor });
141 const threads = await findThreadsByChannel({
142 channelId: channel.id,
143 cursor,
144 limit: 25,
145 });
146
147 if (!threads?.length) break;
148
149 logger.log({
150 channelName,
151 'saveAllThreadsTransaction startedAt': new Date(),
152 });
153
154 for (const thread of threads) {
155 try {
156 await fetchAndPersist(
157 fetchReplies,
158 thread,
159 channel,
160 token,
161 usersInDb,

Callers 2

syncWrapperFunction · 0.90

Calls 5

findThreadsByChannelFunction · 0.90
updateNextPageCursorFunction · 0.90
fetchAndPersistFunction · 0.85
logMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected