fix: pull-sync now reconciles per-field so Outlook star reflects locally

The previous timestamp gate (`if (remoteUpdated <= localUpdated) continue`)
hid genuine remote-side changes because every prior no-op pull bumped
lastSyncedAt to "now", making it newer than the Outlook lastModifiedDateTime
of a subsequent star toggle. Now the pull does a per-field comparison and
only writes lastSyncedAt when at least one field actually changed. Same fix
applied to the Google Tasks pull branch for consistency.

Also run a pull-sync once on mount instead of waiting up to 15 min, so
remote-side changes show up immediately on next page load.

v1.103.2

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
mARTin-B78 2026-05-03 21:27:22 +02:00
parent bf2819ce67
commit f61f5ddb7a
4 changed files with 35 additions and 43 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "my-weekly-todo-list", "name": "my-weekly-todo-list",
"version": "1.103.1", "version": "1.103.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "my-weekly-todo-list", "name": "my-weekly-todo-list",
"version": "1.103.1", "version": "1.103.2",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@auth/prisma-adapter": "^2.11.1", "@auth/prisma-adapter": "^2.11.1",

View File

@ -1,6 +1,6 @@
{ {
"name": "my-weekly-todo-list", "name": "my-weekly-todo-list",
"version": "1.103.1", "version": "1.103.2",
"description": "A web-based weekly task management application that organizes to-dos and calendar events in a single, intuitive weekly view", "description": "A web-based weekly task management application that organizes to-dos and calendar events in a single, intuitive weekly view",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@ -144,11 +144,8 @@ export async function GET(req: NextRequest) {
continue; continue;
} }
const remoteUpdated = new Date(remote.updated); // Field-by-field reconciliation (see Outlook block for rationale).
const localUpdated = localTask.lastSyncedAt || localTask.updatedAt; const updateData: any = {};
if (remoteUpdated <= localUpdated) continue;
const updateData: any = { lastSyncedAt: new Date() };
const remoteCompleted = remote.status === 'completed'; const remoteCompleted = remote.status === 'completed';
if (remoteCompleted !== localTask.completed) { if (remoteCompleted !== localTask.completed) {
@ -173,17 +170,13 @@ export async function GET(req: NextRequest) {
updateData.parentTaskId = null; updateData.parentTaskId = null;
} }
if (Object.keys(updateData).length > 1) { if (Object.keys(updateData).length > 0) {
updateData.lastSyncedAt = new Date();
await prisma.task.update({ await prisma.task.update({
where: { id: localTask.id }, where: { id: localTask.id },
data: updateData data: updateData
}); });
updated++; updated++;
} else {
await prisma.task.update({
where: { id: localTask.id },
data: { lastSyncedAt: new Date() }
});
} }
} }
@ -295,11 +288,13 @@ export async function GET(req: NextRequest) {
continue; continue;
} }
const remoteUpdated = new Date(remote.lastModifiedDateTime); // Field-by-field reconciliation: always check each field and update if it
const localUpdated = localTask.lastSyncedAt || localTask.updatedAt; // differs from remote. Local-side mutations are pushed eagerly via
if (remoteUpdated <= localUpdated) continue; // /api/tasks PATCH, so a remote-side change is the authoritative source
// when fields disagree at pull time. (A timestamp gate here was previously
const updateData: any = { lastSyncedAt: new Date() }; // too strict — bumping lastSyncedAt on no-op pulls hid genuine remote
// changes such as the importance "star" being toggled in Outlook.)
const updateData: any = {};
const remoteCompleted = isMsTodoTaskCompleted(remote.status); const remoteCompleted = isMsTodoTaskCompleted(remote.status);
if (remoteCompleted !== localTask.completed) { if (remoteCompleted !== localTask.completed) {
@ -332,17 +327,13 @@ export async function GET(req: NextRequest) {
updateData.scheduledDate = remoteDue; updateData.scheduledDate = remoteDue;
} }
if (Object.keys(updateData).length > 1) { if (Object.keys(updateData).length > 0) {
updateData.lastSyncedAt = new Date();
await prisma.task.update({ await prisma.task.update({
where: { id: localTask.id }, where: { id: localTask.id },
data: updateData data: updateData
}); });
updated++; updated++;
} else {
await prisma.task.update({
where: { id: localTask.id },
data: { lastSyncedAt: new Date() }
});
} }
} }

View File

@ -2002,28 +2002,29 @@ export default function WeeklyView() {
} }
}, []); }, []);
// Periodic pull-sync from external task providers (every 15 minutes) // Pull-sync from external task providers: once on mount + every 15 minutes.
// The eager mount call makes remote-side changes (e.g. Outlook To-Do star)
// visible immediately on next page load instead of after a 15-minute wait.
useEffect(() => { useEffect(() => {
if (!session) return; if (!session) return;
const interval = setInterval( const runPullSync = async () => {
async () => { try {
try { const res = await fetch("/api/tasks/sync");
const res = await fetch("/api/tasks/sync"); if (res.ok) {
if (res.ok) { const data = await res.json();
const data = await res.json(); if (data.updated > 0 || data.deleted > 0 || data.created > 0) {
if (data.updated > 0 || data.deleted > 0 || data.created > 0) { console.log(
console.log( `[SYNC] Pulled ${data.updated} updates, ${data.deleted} deletions, ${data.created || 0} new tasks`,
`[SYNC] Pulled ${data.updated} updates, ${data.deleted} deletions, ${data.created || 0} new tasks`, );
); fetchTasks();
fetchTasks();
}
} }
} catch (e) {
console.error("[SYNC] Task sync error:", e);
} }
}, } catch (e) {
15 * 60 * 1000, console.error("[SYNC] Task sync error:", e);
); }
};
runPullSync();
const interval = setInterval(runPullSync, 15 * 60 * 1000);
return () => clearInterval(interval); return () => clearInterval(interval);
}, [session]); }, [session]);