1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 17:59:55 +02:00

Improve Cache and encoder

This commit is contained in:
Daniel Neto 2024-08-09 15:27:26 -03:00
parent cafd250944
commit 4a8f82fdc9
5 changed files with 23 additions and 9 deletions

View file

@ -1186,6 +1186,9 @@ abstract class CacheHandler
$timeLog = __FILE__ . "::deleteCache ";
TimeLogStart($timeLog);
$prefix = $this->getCacheSubdir();
if (!class_exists('CachesInDB')) {
AVideoPlugin::loadPlugin('Cache');
}
if (class_exists('CachesInDB')) {
//_error_log("deleteCache CachesInDB prefix=$prefix");
CacheDB::deleteCacheStartingWith($prefix, $schedule);
@ -1193,6 +1196,7 @@ abstract class CacheHandler
TimeLogEnd($timeLog, __LINE__);
unset($_SESSION['user']['sessionCache']);
TimeLogEnd($timeLog, __LINE__);
$dir = ObjectYPT::getTmpCacheDir() . $prefix;
if(!$schedule){
TimeLogEnd($timeLog, __LINE__);
_session_start();
@ -1203,7 +1207,6 @@ abstract class CacheHandler
//_error_log("deleteCache not schedule");
}
TimeLogEnd($timeLog, __LINE__);
$dir = ObjectYPT::getTmpCacheDir() . $prefix;
$resp = exec("rm -R {$dir}");
@ -1211,7 +1214,8 @@ abstract class CacheHandler
return true;
}else{
_error_log("deleteCache schedule");
$resp = execAsync("rm -R {$dir}");
//_error_log("deleteCache schedule ".json_encode(debug_backtrace()));
return false;
}
}

View file

@ -64,7 +64,7 @@ _error_log("aVideoEncoder.json: start to receive: " . json_encode($_REQUEST));
// check if there is en video id if yes update if is not create a new one
$video = new Video("", "", @$_REQUEST['videos_id'], true);
if (!empty($video->getId()) && !empty($_REQUEST['first_request'])) {
if (!empty($video->getId()) && !empty($_REQUEST['first_request']) && !empty($_REQUEST['downloadURL'])) {
_error_log("aVideoEncoder.json: There is a new video to replace the existing one, we will delete the current files videos_id = " . $video->getId());
$video->removeVideoFiles();
}
@ -169,6 +169,7 @@ if (!empty($_FILES['video']['tmp_name'])) {
} else {
// set encoding
$video->setStatus(Video::$statusEncoding);
//$video->setAutoStatus(Video::$statusActive);
}
if (!empty($_FILES['image']['tmp_name']) && !file_exists("{$destination_local}.jpg")) {
if (!move_uploaded_file($_FILES['image']['tmp_name'], "{$destination_local}.jpg")) {
@ -192,7 +193,6 @@ if (!empty($_REQUEST['encoderURL'])) {
if (!empty($_REQUEST['categories_id'])) {
$video->setCategories_id($_REQUEST['categories_id']);
}
$video_id = $video->save();
$video->updateDurationIfNeed();
$video->updateHLSDurationIfNeed();

View file

@ -195,9 +195,14 @@ class PlayList extends ObjectYPT
TimeLogStart($TimeLog1);
$cacheName = md5($sql . json_encode($values));
$cacheHandler = new PlayListUserCacheHandler($userId);
//playlist cache
$rows = $cacheHandler->getCache($cacheName, rand(300, 3600));
if (!empty($rows)) {
return object_to_array($rows);
//_error_log("playlist getAllFromUser($userId) cache ");
$rows = object_to_array($rows);
//$rows['return'] = __LINE__;
//$rows['userId'] = $userId;
return $rows;
}
$res = sqlDAL::readSql($sql, $formats, $values, $refreshCacheFromPlaylist);
$fullData = sqlDAL::fetchAllAssoc($res);
@ -578,7 +583,7 @@ class PlayList extends ObjectYPT
reloadSearchVar();
$_POST['sort'] = $sort;
//playlist cache
$cacheHandler = new PlayListCacheHandler($playlists_id);
$cacheObj = $cacheHandler->getCache(md5($sql), 0);
$rows = object_to_array($cacheObj);
@ -634,6 +639,8 @@ class PlayList extends ObjectYPT
//die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
$rows = [];
}
}else{
_error_log("playlist getVideosFromPlaylist($playlists_id) cache ");
}
return $rows;
}
@ -947,10 +954,10 @@ class PlayList extends ObjectYPT
$this->id = $playlists_id;
$cacheHandler = new PlayListCacheHandler($this->id);
$cacheHandler->deleteCache();
$cacheHandler->deleteCache(false, false);
$cacheHandler = new PlayListUserCacheHandler($this->users_id);
$cacheHandler->deleteCache();
$cacheHandler->deleteCache(false, false);
return $playlists_id;
}

View file

@ -905,7 +905,7 @@ if (!class_exists('Video')) {
}
clearCache(true);
} else {
_error_log("Video::setStatus({$status}) [{$this->status}] ");
_error_log("Video::setStatus({$status}) [{$this->status}] ". json_encode(array($_REQUEST, debug_backtrace())));
}
}
AVideoPlugin::onVideoSetStatus($this->id, $this->status, $status);
@ -3012,6 +3012,7 @@ if (!class_exists('Video')) {
{
$filename = $this->getFilename();
if (empty($filename)) {
_error_log("removeVideoFiles filename is empty ");
return false;
}
try {
@ -3024,6 +3025,7 @@ if (!class_exists('Video')) {
if (!empty($cdn)) {
$cdn_obj = $cdn->getDataObject();
if (!empty($cdn_obj->enable_storage) && !empty($this->getSites_id())) {
_error_log("removeVideoFiles CDN Storage ");
CDNStorage::deleteRemoteDirectoryFromFilename($filename);
}
}

View file

@ -22,6 +22,7 @@ class CacheDB
{
if($schedule){
//insert
//_error_log("CacheDB::deleteCacheStartingWith($name) scheduled");
return Cache_schedule_delete::insert($name);
}else{
try {