Skip to content

Add metadata change detection to optimize video update process #1363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions lib/Models/Videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,11 @@ public function haveCoursePerm(string $course_perm, string $user_id = null)
* Updates the metadata related to this video in both opencast and local and runs republish-metadata workflow
*
* @param object $event the updated version of the event
* @param boolean $check_dirty_state whether to check for dirty state, meaning if any of the fields that need the opencast update has changed!
*
* @return boolean the result of updating process
*/
public function updateMetadata($event)
public function updateMetadata($event, $check_dirty_state = true)
{
$api_event_client = ApiEventsClient::getInstance($this->config_id);

Expand All @@ -737,21 +738,34 @@ public function updateMetadata($event)
'subject', 'language', 'description', 'startDate'];
$metadata = [];

// A dirty state flag to check if any of the fields that need the opencast update has changed!
$is_dirty = false;

foreach ($allowed_metadata_fields as $field_name) {
if (isset($event[$field_name])) {
$current_value = $this->getValue($field_name) ?? null;
$value = $event[$field_name];
$id = $field_name;
if ($field_name == 'subject') {
$id = 'subjects';
$value = [$value];
$current_value = [$current_value];
}
if ($field_name == 'presenters') {
$id = 'creator';
$value = array_map('trim', explode(',', $value));
$value = array_filter(array_map('trim', explode(',', $value)));
$current_value = array_filter(array_map('trim', explode(',', $current_value)));
}
if ($field_name == 'contributors') {
$id = 'contributor';
$value = array_map('trim', explode(',', $value));
$value = array_filter(array_map('trim', explode(',', $value)));
$current_value = array_filter(array_map('trim', explode(',', $current_value)));
}

// If it is not yet marked dirty, check for dirty state!
if (!$is_dirty) {
// Assuming that the current value is not the same as the requested value!
$is_dirty = !(json_encode($current_value) === json_encode($value));
}

$metadata[] = [
Expand All @@ -761,6 +775,11 @@ public function updateMetadata($event)
}
}

if ($check_dirty_state && !$is_dirty) {
// nothing changed, no need to update!
return true;
}

$success = false;
$response = $api_event_client->updateMetadata($this->episode, $metadata);
$republish = in_array($response['code'], [200, 204]) === true;
Expand Down
4 changes: 2 additions & 2 deletions vueapp/components/Videos/Actions/VideoEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default {
showEditDialog: false,
visibility: null,
visible_timestamp: null,
use_timestamp: false
use_timestamp: false,
}
},

Expand Down Expand Up @@ -240,4 +240,4 @@ export default {
this.checkVisibility();
}
}
</script>
</script>