TheDJ has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/284368

Change subject: Remove transcodes that are no longer enabled
......................................................................

Remove transcodes that are no longer enabled

When looking up the state of transcodes from a file, first check if
these transcodes in the database are still enabled (listed in either
$wgEnabledTranscodeSet or $wgEnabledAudioTranscodeSet). If they are
not, remove them from the database, disk and cache.

Bug: T123849
Change-Id: Id684ffd1128400bcafdff695525d6455ed403e77
---
M WebVideoTranscode/WebVideoTranscode.php
1 file changed, 16 insertions(+), 3 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TimedMediaHandler 
refs/changes/68/284368/1

diff --git a/WebVideoTranscode/WebVideoTranscode.php 
b/WebVideoTranscode/WebVideoTranscode.php
index 9c460f0..4823286 100644
--- a/WebVideoTranscode/WebVideoTranscode.php
+++ b/WebVideoTranscode/WebVideoTranscode.php
@@ -796,7 +796,8 @@
         * @param {Object} File object
         */
        public static function getTranscodeState( $file, $db = false ) {
-               global $wgTranscodeBackgroundTimeLimit;
+               global $wgTranscodeBackgroundTimeLimit, $wgEnabledTranscodeSet, 
$wgEnabledAudioTranscodeSet;
+               $enabledTranscodeSet = array_merge( $wgEnabledTranscodeSet, 
$wgEnabledAudioTranscodeSet );
                $fileName = $file->getName();
                if ( !isset( self::$transcodeState[$fileName] ) ) {
                        if ( $db === false ) {
@@ -810,10 +811,16 @@
                                        __METHOD__,
                                        array( 'LIMIT' => 100 )
                        );
+                       $toRemove = [];
                        $overTimeout = array();
                        $over = $db->timestamp( time() - ( 2 * 
$wgTranscodeBackgroundTimeLimit ) );
                        // Populate the per transcode state cache
                        foreach ( $res as $row ) {
+                               // Remove any transcode derivatives that are no 
longer in the enabled transcode set
+                               if ( !in_array( $row->transcode_key, 
$enabledTranscodeSet ) ) {
+                                       $toRemove[] = $row->transcode_key;
+                                       continue;
+                               }
                                // strip the out the "transcode_" from keys
                                $trascodeState = array();
                                foreach ( $row as $k => $v ) {
@@ -826,6 +833,9 @@
                                        && $row->transcode_time_error == null ) 
{
                                        $overTimeout[] = $row->transcode_key;
                                }
+                       }
+                       if ( count( $toRemove ) ) {
+                               self::removeTranscodes( $file, $toRemove );
                        }
                        if ( $overTimeout ) {
                                $dbw = wfGetDB( DB_MASTER );
@@ -856,12 +866,15 @@
         *
         * also remove the transcode files:
         * @param $file File Object
-        * @param $transcodeKey String Optional transcode key to remove only 
this key
+        * @param $transcodeKey String|array Optional transcode key to remove 
only this key
         */
        public static function removeTranscodes( &$file, $transcodeKey = false 
) {
 
                // if transcode key is non-false, non-null:
-               if ( $transcodeKey ) {
+               if ( $transcodeKey && is_array( $transcodeKey ) ) {
+                       // remove only the set of requested transcodeKey
+                       $removeKeys = $transcodeKey;
+               } elseif ( $transcodeKey ) {
                        // only remove the requested $transcodeKey
                        $removeKeys = array( $transcodeKey );
                } else {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id684ffd1128400bcafdff695525d6455ed403e77
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TimedMediaHandler
Gerrit-Branch: master
Gerrit-Owner: TheDJ <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to