@@ -239,10 +239,19 @@ function getVideosTagsRating($video)
239239
240240function getVideoTags ($ videos_id , $ type = '' )
241241{
242- global $ advancedCustom , $ advancedCustomUser , $ getTags_ ;
242+ global $ advancedCustom , $ advancedCustomUser , $ getTags_, $ _getVideoTagsFunctionInProgress ;
243243 $ tolerance = 0.1 ;
244244 $ tags = [];
245245
246+ if (empty ($ _getVideoTagsFunctionInProgress )) {
247+ $ _getVideoTagsFunctionInProgress = [];
248+ }
249+ $ inProgressKey = "{$ videos_id }_ {$ type }" ;
250+ if (!empty ($ _getVideoTagsFunctionInProgress [$ inProgressKey ])) {
251+ _error_log ("getVideoTags( $ videos_id, $ type) reentry detected, returning empty tags " , AVideoLog::$ WARNING , true );
252+ return [];
253+ }
254+
246255 $ cacheSuffix = "getTags_ {$ type }" ;
247256 $ videoCache = new VideoCacheHandler ('' , $ videos_id );
248257 $ oneToFiveHours = rand (3600 , 18000 ); // 1 to 5 hours
@@ -254,60 +263,71 @@ function getVideoTags($videos_id, $type = '')
254263 return $ getTags_ ;
255264 }
256265
257- $ timeName1 = TimeLogStart ("getVideoTags {$ videos_id }, $ type " );
258- if (empty ($ advancedCustomUser )) {
259- $ advancedCustomUser = AVideoPlugin::getObjectData ("CustomizeUser " );
260- }
261- if (empty ($ advancedCustom )) {
262- $ advancedCustom = AVideoPlugin::getObjectData ("CustomizeAdvanced " );
263- }
264- $ currentPage = getCurrentPage ();
265- $ rowCount = getRowCount ();
266- unsetCurrentPage ();
267- $ _REQUEST ['rowCount ' ] = 1000 ;
268-
269- $ video = new Video ("" , "" , $ videos_id );
266+ $ _getVideoTagsFunctionInProgress [$ inProgressKey ] = 1 ;
267+ $ currentPage = null ;
268+ $ rowCount = null ;
269+ $ requestChanged = false ;
270+ try {
271+ $ timeName1 = TimeLogStart ("getVideoTags {$ videos_id }, $ type " );
272+ if (empty ($ advancedCustomUser )) {
273+ $ advancedCustomUser = AVideoPlugin::getObjectData ("CustomizeUser " );
274+ }
275+ if (empty ($ advancedCustom )) {
276+ $ advancedCustom = AVideoPlugin::getObjectData ("CustomizeAdvanced " );
277+ }
278+ $ currentPage = getCurrentPage ();
279+ $ rowCount = getRowCount ();
280+ unsetCurrentPage ();
281+ $ _REQUEST ['rowCount ' ] = 1000 ;
282+ $ requestChanged = true ;
270283
271- $ timeName2 = TimeLogStart ("getVideoTagsFromVideo {$ videos_id }, $ type " );
272- $ newTags = getVideoTagsFromVideo ($ video , $ type );
273- $ tags = array_merge ($ tags , $ newTags );
274- TimeLogEnd ($ timeName2 , __LINE__ , $ tolerance );
284+ $ video = new Video ("" , "" , $ videos_id );
275285
276- $ timeName2 = TimeLogStart ("getVideoTagVideoStatus {$ videos_id }, $ type " );
277- $ newTags = getVideoTagVideoStatus ($ video , $ type );
278- $ tags = array_merge ($ tags , $ newTags );
279- TimeLogEnd ($ timeName2 , __LINE__ , $ tolerance );
286+ $ timeName2 = TimeLogStart ("getVideoTagsFromVideo {$ videos_id }, $ type " );
287+ $ newTags = getVideoTagsFromVideo ($ video , $ type );
288+ $ tags = array_merge ($ tags , $ newTags );
289+ TimeLogEnd ($ timeName2 , __LINE__ , $ tolerance );
280290
281- $ timeName2 = TimeLogStart ("getVideoTagsGroups {$ videos_id }, $ type " );
282- $ newTags = getVideoTagsGroups ($ video , $ type );
283- $ tags = array_merge ($ tags , $ newTags );
284- TimeLogEnd ($ timeName2 , __LINE__ , $ tolerance );
291+ $ timeName2 = TimeLogStart ("getVideoTagVideoStatus {$ videos_id }, $ type " );
292+ $ newTags = getVideoTagVideoStatus ($ video , $ type );
293+ $ tags = array_merge ($ tags , $ newTags );
294+ TimeLogEnd ($ timeName2 , __LINE__ , $ tolerance );
285295
286- $ timeName2 = TimeLogStart ("getVideosTagsCategory {$ videos_id }, $ type " );
287- $ newTags = getVideosTagsCategory ($ video , $ type );
288- $ tags = array_merge ($ tags , $ newTags );
289- TimeLogEnd ($ timeName2 , __LINE__ , $ tolerance );
296+ $ timeName2 = TimeLogStart ("getVideoTagsGroups {$ videos_id }, $ type " );
297+ $ newTags = getVideoTagsGroups ($ video , $ type );
298+ $ tags = array_merge ($ tags , $ newTags );
299+ TimeLogEnd ($ timeName2 , __LINE__ , $ tolerance );
290300
291- $ timeName2 = TimeLogStart ("getVideoTagsSource {$ videos_id }, $ type " );
292- $ newTags = getVideoTagsSource ($ video , $ type );
293- $ tags = array_merge ($ tags , $ newTags );
294- TimeLogEnd ($ timeName2 , __LINE__ , $ tolerance );
301+ $ timeName2 = TimeLogStart ("getVideosTagsCategory {$ videos_id }, $ type " );
302+ $ newTags = getVideosTagsCategory ($ video , $ type );
303+ $ tags = array_merge ($ tags , $ newTags );
304+ TimeLogEnd ($ timeName2 , __LINE__ , $ tolerance );
295305
296- $ timeName2 = TimeLogStart ("getVideosTagsRating {$ videos_id }" );
297- $ newTags = getVideosTagsRating ($ video );
298- $ tags = array_merge ($ tags , $ newTags );
299- TimeLogEnd ($ timeName2 , __LINE__ , $ tolerance );
306+ $ timeName2 = TimeLogStart ("getVideoTagsSource {$ videos_id }, $ type " );
307+ $ newTags = getVideoTagsSource ($ video, $ type );
308+ $ tags = array_merge ($ tags , $ newTags );
309+ TimeLogEnd ($ timeName2 , __LINE__ , $ tolerance );
300310
301- $ timeName2 = TimeLogStart ("AVideoPlugin::getVideoTags {$ videos_id }" );
302- $ newTags = AVideoPlugin::getVideoTags ($ videos_id );
303- if (is_array ($ newTags )) {
311+ $ timeName2 = TimeLogStart ("getVideosTagsRating {$ videos_id }" );
312+ $ newTags = getVideosTagsRating ($ video );
304313 $ tags = array_merge ($ tags , $ newTags );
305- }
306- TimeLogEnd ($ timeName2 , __LINE__ , $ tolerance );
314+ TimeLogEnd ($ timeName2 , __LINE__ , $ tolerance );
307315
308- TimeLogEnd ($ timeName1 , __LINE__ , $ tolerance * 2 );
309- $ _REQUEST ['current ' ] = $ currentPage ;
310- $ _REQUEST ['rowCount ' ] = $ rowCount ;
316+ $ timeName2 = TimeLogStart ("AVideoPlugin::getVideoTags {$ videos_id }" );
317+ $ newTags = AVideoPlugin::getVideoTags ($ videos_id );
318+ if (is_array ($ newTags )) {
319+ $ tags = array_merge ($ tags , $ newTags );
320+ }
321+ TimeLogEnd ($ timeName2 , __LINE__ , $ tolerance );
322+
323+ TimeLogEnd ($ timeName1 , __LINE__ , $ tolerance * 2 );
324+ } finally {
325+ if ($ requestChanged ) {
326+ $ _REQUEST ['current ' ] = $ currentPage ;
327+ $ _REQUEST ['rowCount ' ] = $ rowCount ;
328+ }
329+ unset($ _getVideoTagsFunctionInProgress [$ inProgressKey ]);
330+ }
311331
312332 $ videoCache ->setCache ($ tags );
313333 //ObjectYPT::setCache($index, $tags);
0 commit comments