Added affected scenes to revision history.

This commit is contained in:
2026-11-21 03:39:34 +01:00
parent e9f7941c39
commit ac762c88c7
3 changed files with 58 additions and 3 deletions
+1
View File
@@ -2,6 +2,7 @@ export function curateRevision(revision) {
return {
id: revision.id,
sceneId: revision.scene_id,
affectedSceneIds: revision.affected_scene_ids || [], // actor revisions have none
actorId: revision.actor_id,
base: revision.base,
deltas: revision.deltas,
+27 -1
View File
@@ -1021,7 +1021,12 @@ export async function fetchSceneRevisions(revisionId, filters = {}, reqUser) {
}
if (filters.sceneId) {
builder.where('scenes_revisions.scene_id', filters.sceneId);
// include revisions of other scenes that changed this one, such as removing a relation from the other end
builder.where((sceneBuilder) => {
sceneBuilder
.where('scenes_revisions.scene_id', filters.sceneId)
.orWhereRaw('scenes_revisions.affected_scene_ids @> ARRAY[?]::integer[]', [filters.sceneId]);
});
}
if (filters.isFinalized === false) {
@@ -1153,6 +1158,24 @@ async function applySceneMoviesDelta(sceneId, delta, trx) {
}
}
// other scenes a revision changes, only the scenes whose relation is added or removed, not those it leaves as is
function getAffectedSceneIds(base, deltas) {
const relationsDelta = deltas.find((delta) => delta.key === 'relations');
if (!relationsDelta) {
return [];
}
const baseRelations = base.relations || [];
const baseKeys = new Set(baseRelations.map((relation) => getRelationKey(relation)));
const deltaKeys = new Set(relationsDelta.value.map((relation) => getRelationKey(relation)));
return Array.from(new Set([
...baseRelations.filter((relation) => !deltaKeys.has(getRelationKey(relation))),
...relationsDelta.value.filter((relation) => !baseKeys.has(getRelationKey(relation))),
].map((relation) => relation.sceneId)));
}
// apply the difference between the revision's base and delta, so relations added or removed since are left alone
async function applySceneRelationsDelta(revision, delta, trx) {
const baseKeys = new Set((revision.base.relations || []).map((relation) => getRelationKey(relation)));
@@ -1438,10 +1461,13 @@ export async function createSceneRevision(sceneId, { edits, comment, apply }, re
throw new HttpError('No effective changes provided', 400);
}
const affectedSceneIds = getAffectedSceneIds(baseScene, deltas);
const [revisionEntry] = await knexOwner('scenes_revisions')
.insert({
user_id: reqUser.id,
scene_id: scene.id,
affected_scene_ids: affectedSceneIds,
base: JSON.stringify(baseScene),
deltas: JSON.stringify(deltas),
hash: mj.hash({