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",
|
||||
"version": "1.103.1",
|
||||
"version": "1.103.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "my-weekly-todo-list",
|
||||
"version": "1.103.1",
|
||||
"version": "1.103.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@auth/prisma-adapter": "^2.11.1",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"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",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
@ -144,11 +144,8 @@ export async function GET(req: NextRequest) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const remoteUpdated = new Date(remote.updated);
|
||||
const localUpdated = localTask.lastSyncedAt || localTask.updatedAt;
|
||||
if (remoteUpdated <= localUpdated) continue;
|
||||
|
||||
const updateData: any = { lastSyncedAt: new Date() };
|
||||
// Field-by-field reconciliation (see Outlook block for rationale).
|
||||
const updateData: any = {};
|
||||
|
||||
const remoteCompleted = remote.status === 'completed';
|
||||
if (remoteCompleted !== localTask.completed) {
|
||||
@ -173,17 +170,13 @@ export async function GET(req: NextRequest) {
|
||||
updateData.parentTaskId = null;
|
||||
}
|
||||
|
||||
if (Object.keys(updateData).length > 1) {
|
||||
if (Object.keys(updateData).length > 0) {
|
||||
updateData.lastSyncedAt = new Date();
|
||||
await prisma.task.update({
|
||||
where: { id: localTask.id },
|
||||
data: updateData
|
||||
});
|
||||
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;
|
||||
}
|
||||
|
||||
const remoteUpdated = new Date(remote.lastModifiedDateTime);
|
||||
const localUpdated = localTask.lastSyncedAt || localTask.updatedAt;
|
||||
if (remoteUpdated <= localUpdated) continue;
|
||||
|
||||
const updateData: any = { lastSyncedAt: new Date() };
|
||||
// Field-by-field reconciliation: always check each field and update if it
|
||||
// differs from remote. Local-side mutations are pushed eagerly via
|
||||
// /api/tasks PATCH, so a remote-side change is the authoritative source
|
||||
// when fields disagree at pull time. (A timestamp gate here was previously
|
||||
// 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);
|
||||
if (remoteCompleted !== localTask.completed) {
|
||||
@ -332,17 +327,13 @@ export async function GET(req: NextRequest) {
|
||||
updateData.scheduledDate = remoteDue;
|
||||
}
|
||||
|
||||
if (Object.keys(updateData).length > 1) {
|
||||
if (Object.keys(updateData).length > 0) {
|
||||
updateData.lastSyncedAt = new Date();
|
||||
await prisma.task.update({
|
||||
where: { id: localTask.id },
|
||||
data: updateData
|
||||
});
|
||||
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(() => {
|
||||
if (!session) return;
|
||||
const interval = setInterval(
|
||||
async () => {
|
||||
const runPullSync = async () => {
|
||||
try {
|
||||
const res = await fetch("/api/tasks/sync");
|
||||
if (res.ok) {
|
||||
@ -2021,9 +2022,9 @@ export default function WeeklyView() {
|
||||
} catch (e) {
|
||||
console.error("[SYNC] Task sync error:", e);
|
||||
}
|
||||
},
|
||||
15 * 60 * 1000,
|
||||
);
|
||||
};
|
||||
runPullSync();
|
||||
const interval = setInterval(runPullSync, 15 * 60 * 1000);
|
||||
return () => clearInterval(interval);
|
||||
}, [session]);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user