Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
QUIQQER
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
163
Issues
163
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QUIQQER
QUIQQER
Commits
02689c53
Verified
Commit
02689c53
authored
Dec 19, 2018
by
Jan Wennrich
🏡
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Media Utils now cache time intensive method results
parent
ef62b3dd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
6 deletions
+106
-6
lib/QUI/Projects/Media/Utils.php
lib/QUI/Projects/Media/Utils.php
+106
-6
No files found.
lib/QUI/Projects/Media/Utils.php
View file @
02689c53
...
...
@@ -19,6 +19,18 @@ use QUI\Utils\StringHelper as StringUtils;
*/
class
Utils
{
/**
* Key for the cache where the size of the media folder is stored.
*
*/
const
CACHE_KEY_MEDIA_FOLDER_SIZE
=
"media_folder_size"
;
/**
* Key for the cache where the size of the media cache folder is stored.
*/
const
CACHE_KEY_MEDIA_CACHE_FOLDER_SIZE
=
"media_cache_folder_size"
;
/**
* Returns the item array
* the array is specially adapted for the media center
...
...
@@ -897,28 +909,116 @@ class Utils
/**
* Returns the size of the given project's media folder in bytes
* Returns the size of the given project's media folder in bytes.
* By default the value is returned from cache.
* Only if you really need to get a freshly calculated result, you may set the force parameter to true.
* When using the force parameter expect timeouts since the calculation could take a lot of time.
*
* @param QUI\Projects\Project $Project
* @param boolean $force - Force a calculation of the media folder size. Values aren't returned from cache. Expect timeouts.
*
* @return int
*/
public
static
function
getMediaFolderSizeForProject
(
QUI
\
Projects\Project
$Project
,
$force
=
false
)
{
if
(
$force
)
{
return
self
::
calculateMediaFolderSizeForProject
(
$Project
);
}
try
{
$cacheSize
=
QUI\Cache\Manager
::
get
(
self
::
CACHE_KEY_MEDIA_FOLDER_SIZE
);
}
catch
(
QUI\Cache\Exception
$Exception
)
{
$cacheSize
=
self
::
calculateMediaFolderSizeForProject
(
$Project
);
}
return
$cacheSize
;
}
/**
* Calculates and returns the size of the media folder for a given project in bytes.
* The result is also stored in cache by default. Use the doNotCache parameter to prevent this.
*
* This process may take a lot of time -> Expect timeouts!
*
* @param QUI\Projects\Project $Project - The project to calculate the media folder size for.
* @param boolean $doNotCache - Don't store the result in cache. Off by default.
*
* @return int
*/
p
ublic
static
function
getMediaFolderSizeForProject
(
QUI
\
Projects\Project
$Project
)
p
rotected
static
function
calculateMediaFolderSizeForProject
(
QUI
\
Projects\Project
$Project
,
$doNotCache
=
false
)
{
return
QUI\Utils\System\File
::
getDirectorySize
(
$Project
->
getMedia
()
->
getFullPath
());
$cacheSize
=
QUI\Utils\System\File
::
getDirectorySize
(
$Project
->
getMedia
()
->
getFullPath
());
if
(
$doNotCache
)
{
return
$cacheSize
;
}
try
{
QUI\Cache\Manager
::
set
(
self
::
CACHE_KEY_MEDIA_FOLDER_SIZE
,
$cacheSize
);
}
catch
(
\
Exception
$Exception
)
{
Log
::
writeException
(
$Exception
);
}
return
$cacheSize
;
}
/**
* Returns the size of the given project's media cache folder in bytes
* Returns the size of the given project's media cache folder in bytes.
* By default the value is returned from cache.
* Only if you really need to get a freshly calculated result, you may set the force parameter to true.
* When using the force parameter expect timeouts since the calculation could take a lot of time.
*
* @param QUI\Projects\Project $Project
* @param boolean $force - Force a calculation of the media folder size. Values aren't returned from cache. Expect timeouts.
*
* @return int
*/
public
static
function
getMediaCacheFolderSizeForProject
(
QUI
\
Projects\Project
$Project
)
public
static
function
getMediaCacheFolderSizeForProject
(
QUI
\
Projects\Project
$Project
,
$force
=
false
)
{
return
QUI\Utils\System\File
::
getDirectorySize
(
$Project
->
getMedia
()
->
getFullCachePath
());
if
(
$force
)
{
return
self
::
calculateMediaCacheFolderSizeForProject
(
$Project
);
}
try
{
$cacheSize
=
QUI\Cache\Manager
::
get
(
self
::
CACHE_KEY_MEDIA_CACHE_FOLDER_SIZE
);
}
catch
(
QUI\Cache\Exception
$Exception
)
{
$cacheSize
=
self
::
calculateMediaCacheFolderSizeForProject
(
$Project
);
}
return
$cacheSize
;
}
/**
* Calculates and returns the size of the media cache folder for a given project in bytes.
* The result is also stored in cache by default. Use the doNotCache parameter to prevent this.
*
* This process may take a lot of time -> Expect timeouts!
*
* @param QUI\Projects\Project $Project - The project to calculate the media folder size for.
* @param boolean $doNotCache - Don't store the result in cache. Off by default.
*
* @return int
*/
protected
static
function
calculateMediaCacheFolderSizeForProject
(
QUI
\
Projects\Project
$Project
,
$doNotCache
=
false
)
{
$cacheSize
=
QUI\Utils\System\File
::
getDirectorySize
(
$Project
->
getMedia
()
->
getFullCachePath
());
if
(
$doNotCache
)
{
return
$cacheSize
;
}
try
{
QUI\Cache\Manager
::
set
(
self
::
CACHE_KEY_MEDIA_CACHE_FOLDER_SIZE
,
$cacheSize
);
}
catch
(
\
Exception
$Exception
)
{
Log
::
writeException
(
$Exception
);
}
return
$cacheSize
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment