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:
parent
bf2819ce67
commit
f61f5ddb7a
4
package-lock.json
generated
4
package-lock.json
generated
@ -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",
|
||||||
|
|||||||
@ -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": {
|
||||||
|
|||||||
@ -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() }
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2002,11 +2002,12 @@ 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) {
|
||||||
@ -2021,9 +2022,9 @@ export default function WeeklyView() {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("[SYNC] Task sync error:", e);
|
console.error("[SYNC] Task sync error:", e);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
15 * 60 * 1000,
|
runPullSync();
|
||||||
);
|
const interval = setInterval(runPullSync, 15 * 60 * 1000);
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, [session]);
|
}, [session]);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user