This commit is contained in:
Rizky 2024-08-15 12:02:58 +07:00
parent 4c158cf1b3
commit ec687fe052
1 changed files with 33 additions and 32 deletions

View File

@ -42,45 +42,46 @@ export const yjs_diff_local: SAction["yjs"]["diff_local"] = async function (
ts: history[id], ts: history[id],
}, },
}); });
setTimeout(async () => {
const res = await _db.page_history.findMany({
where: {
id_page: id,
},
select: {
id: true,
ts: true,
},
orderBy: {
ts: "desc",
},
});
const ids: string[] = [];
const res = await _db.page_history.findMany({ let last_ts = 0;
where: { let last_stacked = false;
id_page: id, for (let i = 0; i < res.length; i++) {
}, const ts = parseInt(res[i].ts);
select: {
id: true,
ts: true,
},
orderBy: {
ts: "desc",
},
});
const ids: string[] = [];
let last_ts = 0; if (!last_ts) last_ts = ts;
let last_stacked = false;
for (let i = 0; i < res.length; i++) {
const ts = parseInt(res[i].ts);
if (!last_ts) last_ts = ts; if (i > 25) {
if (!last_stacked) {
if (i > 25) { if (((last_ts - ts) / 1000) * 60 < 10) {
if (!last_stacked) { last_stacked = true;
if (((last_ts - ts) / 1000) * 60 < 10) { ids.push(res[i].id);
last_stacked = true; }
ids.push(res[i].id); } else {
last_stacked = false;
} }
} else {
last_stacked = false;
} }
last_ts = ts;
} }
last_ts = ts; _db.page_history.deleteMany({
} where: { id: { in: ids } },
await _db.page_history.deleteMany({ });
where: { id: { in: ids } },
}); });
} else { } else {
await _db.page_history.updateMany({ _db.page_history.updateMany({
data: { data: {
content_tree: await gzipAsync(JSON.stringify(root.toJSON())), content_tree: await gzipAsync(JSON.stringify(root.toJSON())),
}, },
@ -91,7 +92,7 @@ export const yjs_diff_local: SAction["yjs"]["diff_local"] = async function (
}); });
} }
await _db.page.update({ _db.page.update({
where: { id }, where: { id },
data: { data: {
content_tree: root.toJSON(), content_tree: root.toJSON(),