$NetBSD: patch-uniqid,v 1.1 2025/03/03 15:21:05 manu Exp $
Avoid uniqid() for performance sake
uniqid() provides time-based unique idenfitiers. In order to avoid
collisions, it waits for time to elapse. Depending on PHP version,
this is done by sleeping or by polling the gettimeofday() system
call, both approach being rather inefficient. uniqid() may take a
few dozen of milliseconds to return, and it is called very often
to build a page.
AVideo implements _uniqid() which provides random-based unique
identifiers. This change replace uniqid() calls by _uniqid() to
improve performances.
Backport of upstream https://github.com/WWBN/AVideo/pull/9905
--- ./admin/functions.php.orig 2025-03-01 02:04:58.172236792 +0100
+++ ./admin/functions.php 2025-03-01 02:04:58.186281699 +0100
@@ -64,9 +64,9 @@
}
$elements[] = "
{$label} {$input}{$help} ";
} elseif (is_bool($valueJson)) {
//var_dump($keyJson, $valueJson, '--- ');
- $id = uniqid();
+ $id = _uniqid();
$input = '
';
@@ -85,9 +85,9 @@
$input = ''.__('Buy this plugin now').' ';
} else {
$plugin = AVideoPlugin::loadPluginIfEnabled($pluginName);
$pluginForced = AVideoPlugin::loadPlugin($pluginName);
- $id = uniqid();
+ $id = _uniqid();
$uuid = $pluginForced->getUUID();
$input = '
--- ./admin/index.php.orig 2025-03-01 02:04:58.189556384 +0100
+++ ./admin/index.php 2025-03-01 02:04:58.193064864 +0100
@@ -233,9 +233,9 @@
if (empty($_REQUEST['page'])) {
$panel = 'panel-primary';
}
foreach ($itens as $key => $value) {
- $uid = uniqid();
+ $uid = _uniqid();
$href = 'data-toggle="collapse" data-parent="#accordion" href="#collapse' . $uid . '"';
if (!empty($value->href)) {
$href = 'href="' . $global['webSiteRootURL'] . 'admin/?page=' . $value->href . '"';
}
--- ./install/checkConfiguration.php.orig 2025-03-01 02:04:58.196364835 +0100
+++ ./install/checkConfiguration.php 2025-03-01 02:06:52.684806806 +0100
@@ -182,9 +182,9 @@
error_log("Installation: ".__LINE__);
$mysqli->close();
if (empty($_POST['salt'])) {
- $_POST['salt'] = uniqid();
+ $_POST['salt'] = _uniqid();
}
$content = "setDuration("00:00:45");
$video->setType('video');
--- ./install/recoverFilesToVideos.php.orig 2025-03-01 02:04:58.216646519 +0100
+++ ./install/recoverFilesToVideos.php 2025-03-01 02:04:58.220037871 +0100
@@ -14,9 +14,9 @@
//foreach (glob("../videos/*.{" . implode(",", $fileExtensions) . "}", GLOB_BRACE) as $filename) {
foreach (glob("../videos/*", GLOB_BRACE) as $filename) {
$base = basename($filename);
if (is_dir($filename)) {
- if (strpos($base, "_YPTuniqid_") !== false || strpos($base, "video_2") !== false || strpos($base, "v_2") !== false) {
+ if (strpos($base, "_YPT_uniqid_") !== false || strpos($base, "video_2") !== false || strpos($base, "v_2") !== false) {
$files[$base] = [$base, $filename];
}
} else {
$types = ['_HD', '_Low', '_SD'];
--- ./objects/ICS.php.orig 2025-03-01 02:04:58.223300045 +0100
+++ ./objects/ICS.php 2025-03-01 02:04:58.226764913 +0100
@@ -118,9 +118,9 @@
}
// Set some default values
$props['DTSTAMP'] = $this->format_timestamp('now');
- $props['UID'] = uniqid();
+ $props['UID'] = _uniqid();
// Append properties
foreach ($props as $k => $v) {
if($k=='VALARM'){
--- ./objects/Object.php.orig 2025-03-01 02:04:58.230190991 +0100
+++ ./objects/Object.php 2025-03-01 02:04:58.233967154 +0100
@@ -786,9 +786,9 @@
unset($__getAVideoCache);
//_error_log('deleteALLCache: '.json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)));
$tmpDir = self::getCacheDir('', false);
- $newtmpDir = rtrim($tmpDir, DIRECTORY_SEPARATOR) . uniqid();
+ $newtmpDir = rtrim($tmpDir, DIRECTORY_SEPARATOR) . _uniqid();
_error_log("deleteALLCache rename($tmpDir, $newtmpDir) ");
@rename($tmpDir, $newtmpDir);
if (is_dir($tmpDir)) {
_error_log('deleteALLCache 1 rmdir ' . $tmpDir);
--- ./objects/aVideoQueueEncoder.json.php.orig 2025-03-01 02:04:58.237278647 +0100
+++ ./objects/aVideoQueueEncoder.json.php 2025-03-01 02:04:58.240763036 +0100
@@ -110,9 +110,9 @@
/**
* Make a better title and clean title
*/
$videoNewTitle = $video->getTitle();
- $titleParts = explode("YPTuniqid", $videoNewTitle);
+ $titleParts = explode("YPT_uniqid", $videoNewTitle);
$video->setTitle($titleParts[0]);
$video->setClean_title($titleParts[0]);
}
$id = $video->save($updateVideoGroups);
--- ./objects/category.php.orig 2025-03-01 02:04:58.244112511 +0100
+++ ./objects/category.php 2025-03-01 02:04:58.247843866 +0100
@@ -156,9 +156,9 @@
// check if clean name exists
$exists = $this->getCategoryByName($this->clean_name);
if (!empty($exists) && $exists['id'] !== $this->id) {
- $this->clean_name .= uniqid();
+ $this->clean_name .= _uniqid();
}
$this->nextVideoOrder = intval($this->nextVideoOrder);
$this->parentId = intval($this->parentId);
--- ./objects/functionCroppie.php.orig 2025-03-01 02:04:58.251103210 +0100
+++ ./objects/functionCroppie.php 2025-03-01 02:04:58.254529504 +0100
@@ -40,9 +40,9 @@
$boundary = 0;
}
$boundaryWidth = $viewportWidth + $boundary;
$boundaryHeight = $viewportHeight + $boundary;
- $uid = uniqid();
+ $uid = _uniqid();
$varsArray = [
'buttonTitle' => $buttonTitle,
'callBackJSFunction' => $callBackJSFunction,
--- ./objects/functionInfiniteScroll.php.orig 2025-03-01 02:04:58.257821708 +0100
+++ ./objects/functionInfiniteScroll.php 2025-03-01 02:04:58.261283555 +0100
@@ -56,9 +56,9 @@
}
$isInfiniteScroll = !empty($infinityScrollGetFromSelector) && !empty($infinityScrollAppendIntoSelector);
- $uid = uniqid();
+ $uid = _uniqid();
if ($total < $maxVisible) {
$maxVisible = $total;
}
--- ./objects/functiongetShareMenu.php.orig 2025-03-01 02:04:58.264588743 +0100
+++ ./objects/functiongetShareMenu.php 2025-03-01 02:04:58.268090984 +0100
@@ -54,9 +54,9 @@
$url = $permaLink;
//$title = urlencode($title);
include $global['systemRootPath'] . 'view/include/social.php';
$type = 'animate__flipInX';
- $loaderSequenceName = uniqid();
+ $loaderSequenceName = _uniqid();
?>
(Iframe):
@@ -85,9 +85,9 @@
disableEmailSharing)) {
- $loaderSequenceName = uniqid();
+ $loaderSequenceName = _uniqid();
?>
@@ -165,9 +165,9 @@
--- ./objects/functions.php.orig 2025-03-01 02:04:58.272126408 +0100
+++ ./objects/functions.php 2025-03-01 02:04:58.277603545 +0100
@@ -1604,9 +1604,9 @@
}
function getVideoImagewithHoverAnimation($relativePath, $relativePathHoverAnimation = '', $title = '', $preloadImage = false, $doNotUseAnimatedGif = false)
{
- $id = uniqid();
+ $id = _uniqid();
//getImageTagIfExists($relativePath, $title = '', $id = '', $style = '', $class = 'img img-responsive', $lazyLoad = false, $preloadImage=false)
$img = getImageTagIfExists($relativePath, $title, "thumbsJPG{$id}", '', 'thumbsJPG img img-responsive', false, $preloadImage) . PHP_EOL;
if (empty($doNotUseAnimatedGif) && !empty($relativePathHoverAnimation) && empty($_REQUEST['noImgGif'])) {
$img .= getImageTagIfExists($relativePathHoverAnimation, $title, "thumbsGIF{$id}", 'position: absolute; top: 0;', 'thumbsGIF img img-responsive ', $preloadImage) . PHP_EOL;
@@ -4118,9 +4118,9 @@
}
function getButtontCopyToClipboard($elemToCopyId, $attributes = 'class="btn btn-default btn-sm btn-xs pull-right"', $label = "Copy to Clipboard")
{
- $id = "getButtontCopyToClipboard" . uniqid();
+ $id = "getButtontCopyToClipboard" . _uniqid();
?>
data-toggle="tooltip" data-placement="left" title="">
";
}
function getServerClock()
{
- $id = uniqid();
+ $id = _uniqid();
$today = getdate();
$html = '00:00:00 ';
$html .= "