jenkins-bot has submitted this change and it was merged.

Change subject: Improve transcode job insertion deduping
......................................................................


Improve transcode job insertion deduping

Bug: T89977
Change-Id: I9a739795e1c445b8e4cd923d354eb986ad15997e
---
M WebVideoTranscode/WebVideoTranscode.php
1 file changed, 22 insertions(+), 48 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/WebVideoTranscode/WebVideoTranscode.php 
b/WebVideoTranscode/WebVideoTranscode.php
index adf3c03..cd620f0 100644
--- a/WebVideoTranscode/WebVideoTranscode.php
+++ b/WebVideoTranscode/WebVideoTranscode.php
@@ -864,67 +864,41 @@
         * @param $transcodeKey String transcode key
         */
        public static function updateJobQueue( &$file, $transcodeKey ){
-               global $wgMemc;
-
                $fileName = $file->getTitle()->getDbKey();
                $db = $file->repo->getMasterDB();
 
-               // Check if we need to update the transcode state:
                $transcodeState = self::getTranscodeState( $file, $db );
-               // Check if the job has been added:
-               if( !isset( $transcodeState[ $transcodeKey ] )
-                       || is_null( $transcodeState[ $transcodeKey 
]['time_addjob'] )
-               ) {
-                       // Avoid lock wait timeout due to duplicated work
-                       $cKey = wfMemcKey( 'transcode', md5( $fileName ), 
$transcodeKey );
-                       if ( !$wgMemc->lock( $cKey, 1 ) ) {
-                               return; // assume another process is doing this
-                       }
-                       $unlocker = new ScopedCallback( function() use ( $cKey 
) {
-                               global $wgMemc;
-                               $wgMemc->unlock( $cKey );
-                       } );
 
-                       // update the transcode state:
-                       if( ! isset( $transcodeState[$transcodeKey] ) ){
-                               // insert the transcode row with jobadd time
-                               $db->insert(
-                                       'transcode',
-                                       array(
-                                               'transcode_image_name' => 
$fileName,
-                                               'transcode_key' => 
$transcodeKey,
-                                               'transcode_time_addjob' => 
$db->timestamp(),
-                                               'transcode_error' => "",
-                                               'transcode_final_bitrate' => 0
-                                       ),
-                                       __METHOD__,
-                                       array( 'IGNORE' )
-                               );
-                       } else {
-                               // update job start time
-                               $db->update(
-                                       'transcode',
-                                       array(
-                                               'transcode_time_addjob' => 
$db->timestamp()
-                                       ),
-                                       array(
-                                               'transcode_image_name' => 
$fileName,
-                                               'transcode_key' => 
$transcodeKey,
-                                       ),
-                                       __METHOD__
-                               );
+               // If the job hasn't been added yet, attempt to do so
+               if ( !isset( $transcodeState[ $transcodeKey ] ) ) {
+                       $db->insert(
+                               'transcode',
+                               array(
+                                       'transcode_image_name' => $fileName,
+                                       'transcode_key' => $transcodeKey,
+                                       'transcode_time_addjob' => 
$db->timestamp(),
+                                       'transcode_error' => "",
+                                       'transcode_final_bitrate' => 0
+                               ),
+                               __METHOD__,
+                               array( 'IGNORE' )
+                       );
+
+                       if ( !$db->affectedRows() ) {
+                               // There is already a row for that job added by 
another request, no need to continue
+                               return;
                        }
-                       // Add to job queue and update the db
+
                        $job = new WebVideoTranscodeJob( $file->getTitle(), 
array(
                                'transcodeMode' => 'derivative',
                                'transcodeKey' => $transcodeKey,
                        ) );
-                       $jobId = $job->insert();
-                       if( $jobId ){
+
+                       if ( $job->insert() ) {
                                // Clear the state cache ( now that we have 
updated the page )
                                self::clearTranscodeCache( $fileName );
                        } else {
-                               //adding job failed, update transcode
+                               // Adding job failed, update transcode row
                                $db->update(
                                        'transcode',
                                        array(

-- 
To view, visit https://gerrit.wikimedia.org/r/194333
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9a739795e1c445b8e4cd923d354eb986ad15997e
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/TimedMediaHandler
Gerrit-Branch: master
Gerrit-Owner: Gilles <gdu...@wikimedia.org>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Brian Wolff <bawolff...@gmail.com>
Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org>
Gerrit-Reviewer: Gilles <gdu...@wikimedia.org>
Gerrit-Reviewer: MarkTraceur <mtrac...@member.fsf.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to