feat: narrow thread sync context and dedupe realtime refresh
This commit is contained in:
@@ -7161,7 +7161,7 @@ export async function upsertDeviceHeartbeat(payload: {
|
||||
sourceTaskId: `heartbeat-${candidate.candidateId}`,
|
||||
});
|
||||
}
|
||||
if (shouldQueueProjectUnderstandingSync(matchingProject, candidate.lastActiveAt, state)) {
|
||||
if (shouldQueueProjectUnderstandingSync(matchingProject, candidate.lastActiveAt, state, "heartbeat_activity")) {
|
||||
projectUnderstandingSyncRequests.push({
|
||||
projectId: matchingProject.id,
|
||||
observedActivityAt: candidate.lastActiveAt,
|
||||
@@ -7601,7 +7601,12 @@ function buildProjectUnderstandingTakeoverNotice(projectName: string, snapshot:
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
function shouldQueueProjectUnderstandingSync(project: Project, observedActivityAt: string, state: BossState) {
|
||||
function shouldQueueProjectUnderstandingSync(
|
||||
project: Project,
|
||||
observedActivityAt: string,
|
||||
state: BossState,
|
||||
reason: "heartbeat_activity" | "thread_reply" = "heartbeat_activity",
|
||||
) {
|
||||
if (!isDispatchableThreadProject(project)) {
|
||||
return false;
|
||||
}
|
||||
@@ -7621,6 +7626,9 @@ function shouldQueueProjectUnderstandingSync(project: Project, observedActivityA
|
||||
const hasThreadStatusDocument = state.threadStatusDocuments.some(
|
||||
(item) => item.projectId === project.id && item.threadId === project.threadMeta.threadId,
|
||||
);
|
||||
if (reason === "thread_reply" && hasThreadStatusDocument) {
|
||||
return false;
|
||||
}
|
||||
if (project.projectUnderstanding && hasThreadStatusDocument) {
|
||||
const lastSyncedTs = Date.parse(
|
||||
project.threadMeta.lastProjectUnderstandingSyncedAt ??
|
||||
@@ -7673,7 +7681,7 @@ async function queueProjectUnderstandingSyncTask(input: {
|
||||
}) {
|
||||
const state = await readState();
|
||||
const project = state.projects.find((item) => item.id === input.projectId);
|
||||
if (!project || !shouldQueueProjectUnderstandingSync(project, input.observedActivityAt, state)) {
|
||||
if (!project || !shouldQueueProjectUnderstandingSync(project, input.observedActivityAt, state, input.reason)) {
|
||||
return null;
|
||||
}
|
||||
const requestedByAccount = state.user.account || project.deviceIds[0] || "17600003315";
|
||||
@@ -8625,7 +8633,8 @@ export async function appendProjectMessage(payload: {
|
||||
return {
|
||||
message,
|
||||
shouldQueueUnderstandingSync:
|
||||
shouldTrackThreadProgress && shouldQueueProjectUnderstandingSync(project, message.sentAt, state),
|
||||
shouldTrackThreadProgress &&
|
||||
shouldQueueProjectUnderstandingSync(project, message.sentAt, state, "thread_reply"),
|
||||
};
|
||||
});
|
||||
if (result.shouldQueueUnderstandingSync) {
|
||||
|
||||
Reference in New Issue
Block a user