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:
parent
cafd250944
commit
4a8f82fdc9
5 changed files with 23 additions and 9 deletions
|
@ -1186,6 +1186,9 @@ abstract class CacheHandler
|
||||||
$timeLog = __FILE__ . "::deleteCache ";
|
$timeLog = __FILE__ . "::deleteCache ";
|
||||||
TimeLogStart($timeLog);
|
TimeLogStart($timeLog);
|
||||||
$prefix = $this->getCacheSubdir();
|
$prefix = $this->getCacheSubdir();
|
||||||
|
if (!class_exists('CachesInDB')) {
|
||||||
|
AVideoPlugin::loadPlugin('Cache');
|
||||||
|
}
|
||||||
if (class_exists('CachesInDB')) {
|
if (class_exists('CachesInDB')) {
|
||||||
//_error_log("deleteCache CachesInDB prefix=$prefix");
|
//_error_log("deleteCache CachesInDB prefix=$prefix");
|
||||||
CacheDB::deleteCacheStartingWith($prefix, $schedule);
|
CacheDB::deleteCacheStartingWith($prefix, $schedule);
|
||||||
|
@ -1193,6 +1196,7 @@ abstract class CacheHandler
|
||||||
TimeLogEnd($timeLog, __LINE__);
|
TimeLogEnd($timeLog, __LINE__);
|
||||||
unset($_SESSION['user']['sessionCache']);
|
unset($_SESSION['user']['sessionCache']);
|
||||||
TimeLogEnd($timeLog, __LINE__);
|
TimeLogEnd($timeLog, __LINE__);
|
||||||
|
$dir = ObjectYPT::getTmpCacheDir() . $prefix;
|
||||||
if(!$schedule){
|
if(!$schedule){
|
||||||
TimeLogEnd($timeLog, __LINE__);
|
TimeLogEnd($timeLog, __LINE__);
|
||||||
_session_start();
|
_session_start();
|
||||||
|
@ -1203,7 +1207,6 @@ abstract class CacheHandler
|
||||||
//_error_log("deleteCache not schedule");
|
//_error_log("deleteCache not schedule");
|
||||||
}
|
}
|
||||||
TimeLogEnd($timeLog, __LINE__);
|
TimeLogEnd($timeLog, __LINE__);
|
||||||
$dir = ObjectYPT::getTmpCacheDir() . $prefix;
|
|
||||||
|
|
||||||
$resp = exec("rm -R {$dir}");
|
$resp = exec("rm -R {$dir}");
|
||||||
|
|
||||||
|
@ -1211,7 +1214,8 @@ abstract class CacheHandler
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
_error_log("deleteCache schedule");
|
$resp = execAsync("rm -R {$dir}");
|
||||||
|
//_error_log("deleteCache schedule ".json_encode(debug_backtrace()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// check if there is en video id if yes update if is not create a new one
|
||||||
$video = new Video("", "", @$_REQUEST['videos_id'], true);
|
$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());
|
_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();
|
$video->removeVideoFiles();
|
||||||
}
|
}
|
||||||
|
@ -169,6 +169,7 @@ if (!empty($_FILES['video']['tmp_name'])) {
|
||||||
} else {
|
} else {
|
||||||
// set encoding
|
// set encoding
|
||||||
$video->setStatus(Video::$statusEncoding);
|
$video->setStatus(Video::$statusEncoding);
|
||||||
|
//$video->setAutoStatus(Video::$statusActive);
|
||||||
}
|
}
|
||||||
if (!empty($_FILES['image']['tmp_name']) && !file_exists("{$destination_local}.jpg")) {
|
if (!empty($_FILES['image']['tmp_name']) && !file_exists("{$destination_local}.jpg")) {
|
||||||
if (!move_uploaded_file($_FILES['image']['tmp_name'], "{$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'])) {
|
if (!empty($_REQUEST['categories_id'])) {
|
||||||
$video->setCategories_id($_REQUEST['categories_id']);
|
$video->setCategories_id($_REQUEST['categories_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$video_id = $video->save();
|
$video_id = $video->save();
|
||||||
$video->updateDurationIfNeed();
|
$video->updateDurationIfNeed();
|
||||||
$video->updateHLSDurationIfNeed();
|
$video->updateHLSDurationIfNeed();
|
||||||
|
|
|
@ -195,9 +195,14 @@ class PlayList extends ObjectYPT
|
||||||
TimeLogStart($TimeLog1);
|
TimeLogStart($TimeLog1);
|
||||||
$cacheName = md5($sql . json_encode($values));
|
$cacheName = md5($sql . json_encode($values));
|
||||||
$cacheHandler = new PlayListUserCacheHandler($userId);
|
$cacheHandler = new PlayListUserCacheHandler($userId);
|
||||||
|
//playlist cache
|
||||||
$rows = $cacheHandler->getCache($cacheName, rand(300, 3600));
|
$rows = $cacheHandler->getCache($cacheName, rand(300, 3600));
|
||||||
if (!empty($rows)) {
|
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);
|
$res = sqlDAL::readSql($sql, $formats, $values, $refreshCacheFromPlaylist);
|
||||||
$fullData = sqlDAL::fetchAllAssoc($res);
|
$fullData = sqlDAL::fetchAllAssoc($res);
|
||||||
|
@ -578,7 +583,7 @@ class PlayList extends ObjectYPT
|
||||||
reloadSearchVar();
|
reloadSearchVar();
|
||||||
$_POST['sort'] = $sort;
|
$_POST['sort'] = $sort;
|
||||||
|
|
||||||
|
//playlist cache
|
||||||
$cacheHandler = new PlayListCacheHandler($playlists_id);
|
$cacheHandler = new PlayListCacheHandler($playlists_id);
|
||||||
$cacheObj = $cacheHandler->getCache(md5($sql), 0);
|
$cacheObj = $cacheHandler->getCache(md5($sql), 0);
|
||||||
$rows = object_to_array($cacheObj);
|
$rows = object_to_array($cacheObj);
|
||||||
|
@ -634,6 +639,8 @@ class PlayList extends ObjectYPT
|
||||||
//die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
|
//die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
|
||||||
$rows = [];
|
$rows = [];
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
_error_log("playlist getVideosFromPlaylist($playlists_id) cache ");
|
||||||
}
|
}
|
||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
|
@ -947,10 +954,10 @@ class PlayList extends ObjectYPT
|
||||||
$this->id = $playlists_id;
|
$this->id = $playlists_id;
|
||||||
|
|
||||||
$cacheHandler = new PlayListCacheHandler($this->id);
|
$cacheHandler = new PlayListCacheHandler($this->id);
|
||||||
$cacheHandler->deleteCache();
|
$cacheHandler->deleteCache(false, false);
|
||||||
|
|
||||||
$cacheHandler = new PlayListUserCacheHandler($this->users_id);
|
$cacheHandler = new PlayListUserCacheHandler($this->users_id);
|
||||||
$cacheHandler->deleteCache();
|
$cacheHandler->deleteCache(false, false);
|
||||||
|
|
||||||
return $playlists_id;
|
return $playlists_id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -905,7 +905,7 @@ if (!class_exists('Video')) {
|
||||||
}
|
}
|
||||||
clearCache(true);
|
clearCache(true);
|
||||||
} else {
|
} 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);
|
AVideoPlugin::onVideoSetStatus($this->id, $this->status, $status);
|
||||||
|
@ -3012,6 +3012,7 @@ if (!class_exists('Video')) {
|
||||||
{
|
{
|
||||||
$filename = $this->getFilename();
|
$filename = $this->getFilename();
|
||||||
if (empty($filename)) {
|
if (empty($filename)) {
|
||||||
|
_error_log("removeVideoFiles filename is empty ");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -3024,6 +3025,7 @@ if (!class_exists('Video')) {
|
||||||
if (!empty($cdn)) {
|
if (!empty($cdn)) {
|
||||||
$cdn_obj = $cdn->getDataObject();
|
$cdn_obj = $cdn->getDataObject();
|
||||||
if (!empty($cdn_obj->enable_storage) && !empty($this->getSites_id())) {
|
if (!empty($cdn_obj->enable_storage) && !empty($this->getSites_id())) {
|
||||||
|
_error_log("removeVideoFiles CDN Storage ");
|
||||||
CDNStorage::deleteRemoteDirectoryFromFilename($filename);
|
CDNStorage::deleteRemoteDirectoryFromFilename($filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ class CacheDB
|
||||||
{
|
{
|
||||||
if($schedule){
|
if($schedule){
|
||||||
//insert
|
//insert
|
||||||
|
//_error_log("CacheDB::deleteCacheStartingWith($name) scheduled");
|
||||||
return Cache_schedule_delete::insert($name);
|
return Cache_schedule_delete::insert($name);
|
||||||
}else{
|
}else{
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue