Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MetaGer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
MetaGer
Commits
977b4349
Commit
977b4349
authored
2 years ago
by
Dominik Hebeler
Browse files
Options
Downloads
Patches
Plain Diff
using a faster storage location for script
parent
45b4bef7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
metager/app/Http/Controllers/AdminInterface.php
+49
-5
49 additions, 5 deletions
metager/app/Http/Controllers/AdminInterface.php
with
49 additions
and
5 deletions
metager/app/Http/Controllers/AdminInterface.php
+
49
−
5
View file @
977b4349
...
@@ -9,6 +9,7 @@ use Illuminate\Database\SQLiteConnection;
...
@@ -9,6 +9,7 @@ use Illuminate\Database\SQLiteConnection;
use
Illuminate\Http\Request
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\App
;
use
Illuminate\Support\Facades\App
;
use
Illuminate\Support\Facades\Cache
;
use
Illuminate\Support\Facades\Cache
;
use
Illuminate\Support\Facades\Redis
;
use
PDO
;
use
PDO
;
class
AdminInterface
extends
Controller
class
AdminInterface
extends
Controller
...
@@ -49,9 +50,10 @@ class AdminInterface extends Controller
...
@@ -49,9 +50,10 @@ class AdminInterface extends Controller
$cache_key
=
"admin_count_total_${interface}_${year}_${month}_${day}"
;
$cache_key
=
"admin_count_total_${interface}_${year}_${month}_${day}"
;
$total_count
=
Cache
::
get
(
$cache_key
);
$total_count
=
Cache
::
get
(
$cache_key
);
if
(
$total_count
===
null
)
{
if
(
$total_count
===
null
)
{
$database_file
=
\storage_path
(
"logs/metager/
$year
/
$month
/
$day
.sqli
te
"
);
$database_file
=
$this
->
getDatabaseLogFile
(
$da
te
);
if
(
!
\file_exists
(
$database_file
)
)
{
if
(
$database_file
===
null
)
{
abort
(
404
);
abort
(
404
);
}
}
...
@@ -107,9 +109,8 @@ class AdminInterface extends Controller
...
@@ -107,9 +109,8 @@ class AdminInterface extends Controller
$total_count
=
Cache
::
get
(
$cache_key
);
$total_count
=
Cache
::
get
(
$cache_key
);
if
(
$total_count
===
null
)
{
if
(
$total_count
===
null
)
{
$database_file
=
$this
->
getDatabaseLogFile
(
$date
);
$database_file
=
\storage_path
(
"logs/metager/
$year
/
$month
/
$day
.sqlite"
);
if
(
$database_file
===
null
)
{
if
(
!
\file_exists
(
$database_file
))
{
abort
(
404
);
abort
(
404
);
}
}
...
@@ -211,4 +212,47 @@ class AdminInterface extends Controller
...
@@ -211,4 +212,47 @@ class AdminInterface extends Controller
$status
=
\fpm_get_status
();
$status
=
\fpm_get_status
();
return
response
()
->
json
(
$status
);
return
response
()
->
json
(
$status
);
}
}
private
function
getDatabaseLogFile
(
Carbon
$date
)
{
$original_file
=
\storage_path
(
"logs/metager/"
.
$date
->
format
(
"Y/m/d"
)
.
".sqlite"
);
$fast_file
=
\storage_path
(
"logs/metager/fast_dir/"
.
$date
->
format
(
"Y/m/d"
)
.
".sqlite"
);
if
(
!
\file_exists
(
$original_file
))
{
return
null
;
}
if
(
$date
->
isToday
())
{
return
$original_file
;
}
$lock_hash
=
\md5
(
$fast_file
);
if
(
\file_exists
(
$fast_file
)
&&
Redis
::
get
(
$lock_hash
)
===
null
)
{
return
$fast_file
;
}
// Verify that the target directory exists
$fast_file_dir
=
dirname
(
$fast_file
);
if
(
!
\file_exists
(
$fast_file_dir
)
&&
!
\mkdir
(
$fast_file_dir
,
0777
,
true
))
{
return
null
;
}
// Acquire a lock for this file to make sure we're the only process copying it
do
{
$lock
=
Redis
::
setnx
(
$lock_hash
,
"lock"
);
if
(
$lock
===
1
)
{
Redis
::
expire
(
$lock_hash
,
15
);
}
else
{
\usleep
(
350
*
1000
);
}
}
while
(
$lock
!==
1
);
try
{
if
(
\copy
(
$original_file
,
$fast_file
))
{
return
$fast_file
;
}
}
finally
{
Redis
::
del
(
$lock_hash
);
}
return
null
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment