1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-04 10:19:24 +02:00
Daniel Neto 2024-01-22 11:19:31 -03:00
parent 39c8c0ea06
commit 5bcf87ea81
5 changed files with 44 additions and 19 deletions

View file

@ -1084,7 +1084,16 @@ abstract class CacheHandler {
} }
public function getCache($suffix, $lifetime = 60) { public function getCache($suffix, $lifetime = 60) {
global $_getCache;
if(!isset($_getCache)){
$_getCache = array();
}
$this->setSuffix($suffix); $this->setSuffix($suffix);
$name = $this->getCacheName( $this->suffix);
if(isset($_getCache[$name])){
return $_getCache[$name];
}
if(!empty($lifetime) && !$this->canRefreshCache()){ if(!empty($lifetime) && !$this->canRefreshCache()){
//_error_log("{$suffix} lifetime={$lifetime} cache will not be refreshed now"); //_error_log("{$suffix} lifetime={$lifetime} cache will not be refreshed now");
$lifetime = 0; $lifetime = 0;
@ -1094,6 +1103,7 @@ abstract class CacheHandler {
if(!empty($cache)){ if(!empty($cache)){
self::$cachedResults++; self::$cachedResults++;
} }
$_getCache[$name] = $cache;
return $cache; return $cache;
} }
@ -1129,6 +1139,10 @@ abstract class CacheHandler {
abstract protected function canRefreshCache(); abstract protected function canRefreshCache();
public function hasCache($suffix, $lifetime = 60) {
$cache = $this->getCache($suffix, $lifetime);
return $cache!==null;
}
} }
class VideosListCacheHandler extends CacheHandler { class VideosListCacheHandler extends CacheHandler {

View file

@ -661,9 +661,8 @@ class Category
$timeLogName = TimeLogStart($cacheSuffix); $timeLogName = TimeLogStart($cacheSuffix);
$cacheHandler = new CategoryCacheHandler(0); $cacheHandler = new CategoryCacheHandler(0);
$result = $cacheHandler->getCache($cacheSuffix, 0);
TimeLogEnd($timeLogName, __LINE__); TimeLogEnd($timeLogName, __LINE__);
if (empty($result)) { if (!$cacheHandler->hasCache($cacheSuffix, 0)) {
$videos = self::getTotalVideosFromCategory($categories_id, $showUnlisted, $getAllVideos, $renew); $videos = self::getTotalVideosFromCategory($categories_id, $showUnlisted, $getAllVideos, $renew);
TimeLogEnd($timeLogName, __LINE__); TimeLogEnd($timeLogName, __LINE__);
$lives = self::getTotalLivesFromCategory($categories_id, $showUnlisted, $renew); $lives = self::getTotalLivesFromCategory($categories_id, $showUnlisted, $renew);
@ -675,6 +674,7 @@ class Category
$cacheHandler->setCache($result); $cacheHandler->setCache($result);
TimeLogEnd($timeLogName, __LINE__); TimeLogEnd($timeLogName, __LINE__);
} else { } else {
$result = $cacheHandler->getCache($cacheSuffix, 0);
$result = object_to_array($result); $result = object_to_array($result);
} }
TimeLogEnd($timeLogName, __LINE__); TimeLogEnd($timeLogName, __LINE__);
@ -771,7 +771,7 @@ class Category
$total = $cacheHandler->getCache($suffix); $total = $cacheHandler->getCache($suffix);
TimeLogEnd($timeLogName, __LINE__); TimeLogEnd($timeLogName, __LINE__);
if ($renew || empty($total)) { if ($renew || (empty($total) && $total !== 0 && $total !== '0')) {
$sql = "SELECT count(id) as total FROM videos v WHERE 1=1 AND categories_id = ? "; $sql = "SELECT count(id) as total FROM videos v WHERE 1=1 AND categories_id = ? ";
if (User::isLogged()) { if (User::isLogged()) {

View file

@ -1901,7 +1901,8 @@ if (!class_exists('Video')) {
return $videos; return $videos;
} }
static function userHasAgeToWatchVideo($row){ static function userHasAgeToWatchVideo($row)
{
if ($row['rrating'] == 'ma') { if ($row['rrating'] == 'ma') {
return User::isOver18(); return User::isOver18();
} }
@ -2606,12 +2607,18 @@ if (!class_exists('Video')) {
return $numRows; return $numRows;
} }
static function videoMadeForKidsExists() { static function videoMadeForKidsExists()
{
global $_videoMadeForKidsExists, $advancedCustomUser; global $_videoMadeForKidsExists, $advancedCustomUser;
if (isset($_videoMadeForKidsExists)) { if (isset($_videoMadeForKidsExists)) {
//var_dump(__LINE__);
return $_videoMadeForKidsExists; return $_videoMadeForKidsExists;
} }
if (empty($advancedCustomUser->videosForKids)) { if (empty($advancedCustom)) {
$advancedCustom = AVideoPlugin::getObjectData("CustomizeAdvanced");
}
if (empty($advancedCustom->videosForKids)) {
//var_dump(__LINE__);
return false; return false;
} }
$sql = "SELECT 1 FROM `videos` v WHERE v.`made_for_kids` = 1 "; $sql = "SELECT 1 FROM `videos` v WHERE v.`made_for_kids` = 1 ";
@ -2620,6 +2627,7 @@ if (!class_exists('Video')) {
$res = sqlDAL::readSql($sql); $res = sqlDAL::readSql($sql);
$video = sqlDAL::fetchAssoc($res); $video = sqlDAL::fetchAssoc($res);
//var_dump(__LINE__, $sql, $_videoMadeForKidsExists);
$_videoMadeForKidsExists = $video ? true : false; $_videoMadeForKidsExists = $video ? true : false;
//var_dump($sql, $_videoMadeForKidsExists, $video);exit; //var_dump($sql, $_videoMadeForKidsExists, $video);exit;
return $_videoMadeForKidsExists; return $_videoMadeForKidsExists;
@ -6878,3 +6886,4 @@ AVideoPlugin::loadPlugin('Permissions');
if (User::isAdmin() || Permissions::canModerateVideos()) { if (User::isAdmin() || Permissions::canModerateVideos()) {
$statusThatTheUserCanUpdate[] = [Video::$statusUnpublished, '#B00']; $statusThatTheUserCanUpdate[] = [Video::$statusUnpublished, '#B00'];
} }
//Video::videoMadeForKidsExists();exit;

View file

@ -1,4 +1,5 @@
<?php <?php
//return false;
global $global, $config; global $global, $config;
if (!isset($global['systemRootPath'])) { if (!isset($global['systemRootPath'])) {
require_once '../../../videos/configuration.php'; require_once '../../../videos/configuration.php';

View file

@ -77,6 +77,7 @@ global $avideoLayout;
</li> </li>
<?php <?php
} }
//var_dump(Video::videoMadeForKidsExists());exit;
if (empty($advancedCustomUser->doNotShowLeftProfile)) { if (empty($advancedCustomUser->doNotShowLeftProfile)) {
if (User::isLogged()) { if (User::isLogged()) {
?> ?>