Skip to content

Commit b1a3c6d

Browse files
committed
Add metadata change detection to optimize video update process,
To keep things simple, we first create a non-reactive copy of the event object. We then compare this copy with the current event to detect whether any metadata-related fields have changed. Based on this comparison, we pass a flag to the backend, which decides whether the update metadata call needs to be triggered.
1 parent 2b4ecc8 commit b1a3c6d

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/Routes/Video/VideoUpdate.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ public function __invoke(Request $request, Response $response, $args)
9191
'text' => _('Das Video wurde erfolgreich aktualisiert.')
9292
];
9393

94+
// If changes are only related to local event properties, we don't need to update the metadata on the Opencast server.
95+
if (isset($event['has_metadata_changes']) && $event['has_metadata_changes'] === false) {
96+
return $this->createResponse([
97+
'message' => $message,
98+
], $response->withStatus(200));
99+
}
100+
94101
$update = $video->updateMetadata($event);
95102

96103
if ($update !== true) {

vueapp/components/Videos/Actions/VideoEdit.vue

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ export default {
138138
showEditDialog: false,
139139
visibility: null,
140140
visible_timestamp: null,
141-
use_timestamp: false
141+
use_timestamp: false,
142+
originalEvent: null
142143
}
143144
},
144145
@@ -181,6 +182,24 @@ export default {
181182
};
182183
}
183184
185+
// Decide whether the actual metadata has been changed or not, in order to check if the update metadata against opencast server is needed.
186+
let has_metadata_changes = false;
187+
let non_metadata_fields = ['tags', 'seminar_visibility', 'cid', 'playlist_token']; // These fields are not part of the metadata.
188+
for (const field in this.event) {
189+
if (non_metadata_fields.includes(field)) {
190+
continue;
191+
}
192+
193+
let event_value = JSON.stringify(this.event[field]);
194+
let original_event_value = JSON.stringify(this.originalEvent[field]);
195+
if (event_value !== original_event_value) {
196+
has_metadata_changes = true;
197+
break;
198+
}
199+
}
200+
201+
this.event.has_metadata_changes = has_metadata_changes;
202+
184203
await this.$store.dispatch('updateVideo', this.event)
185204
.then(({ data }) => {
186205
this.$store.dispatch('addMessage', data.message);
@@ -238,6 +257,8 @@ export default {
238257
this.visibility = this.event.seminar_visibility?.visibility;
239258
this.visible_timestamp = this.event.seminar_visibility?.visible_timestamp;
240259
this.checkVisibility();
260+
// Make sure originalEvent is a non-reactive copy of the event.
261+
this.originalEvent = JSON.parse(JSON.stringify(this.event));
241262
}
242263
}
243-
</script>
264+
</script>

0 commit comments

Comments
 (0)