Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
MetaGer
Commits
b08a0808
Commit
b08a0808
authored
Dec 09, 2019
by
Dominik Hebeler
Browse files
important cache writes are now async
parent
ff3409ed
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/CacheHelper.php
0 → 100644
View file @
b08a0808
<?php
namespace
App
;
class
CacheHelper
{
/**
* MetaGer uses a pretty slow harddrive for the configured cache
* That's why we have some processes running to write cache to disk in parallel
*/
public
static
function
put
(
$key
,
$value
,
$timeSeconds
)
{
$cacherItem
=
[
'timeSeconds'
=>
$time
,
'key'
=>
$key
,
'value'
=>
$value
,
];
Redis
::
rpush
(
\
App\Console\Commands\RequestCacher
::
CACHER_QUEUE
,
json_encode
(
$cacherItem
));
}
}
app/Console/Commands/RequestFetcher.php
View file @
b08a0808
...
...
@@ -97,7 +97,7 @@ class RequestFetcher extends Command
$infos
=
curl_getinfo
(
$info
[
"handle"
],
CURLINFO_PRIVATE
);
$infos
=
explode
(
";"
,
$infos
);
$resulthash
=
$infos
[
0
];
$cacheDuration
=
intval
(
$infos
[
1
]);
$cacheDuration
Minutes
=
intval
(
$infos
[
1
]);
$responseCode
=
curl_getinfo
(
$info
[
"handle"
],
CURLINFO_HTTP_CODE
);
$body
=
""
;
...
...
@@ -112,17 +112,16 @@ class RequestFetcher extends Command
$body
=
\
curl_multi_getcontent
(
$info
[
"handle"
]);
}
Redis
::
pipeline
(
function
(
$pipe
)
use
(
$resulthash
,
$body
,
$cacheDuration
)
{
Redis
::
pipeline
(
function
(
$pipe
)
use
(
$resulthash
,
$body
,
$cacheDuration
Minutes
)
{
$pipe
->
set
(
$resulthash
,
$body
);
$pipe
->
expire
(
$resulthash
,
60
);
$cacherItem
=
[
'
cacheDuration
'
=>
$cacheDuration
,
'
hash
'
=>
$resulthash
,
'
body
'
=>
$body
,
'
timeSeconds
'
=>
$cacheDuration
Minutes
*
60
,
'
key
'
=>
$resulthash
,
'
value
'
=>
$body
,
];
$pipe
->
rpush
(
\
App\Console\Commands\RequestCacher
::
CACHER_QUEUE
,
json_encode
(
$cacherItem
));
});
#Cache::put($resulthash, $body, now()->addMinutes($cacheDuration));
\
curl_multi_remove_handle
(
$this
->
multicurl
,
$info
[
"handle"
]);
}
if
(
!
$active
&&
!
$answerRead
)
{
...
...
app/Http/Middleware/HumanVerification.php
View file @
b08a0808
...
...
@@ -50,7 +50,7 @@ class HumanVerification
# Get all Users of this IP
$users
=
Cache
::
get
(
$prefix
.
"."
.
$id
,
[]);
$users
=
$this
->
removeOldUsers
(
$users
);
$users
=
$this
->
removeOldUsers
(
$prefix
,
$users
);
$user
=
[];
if
(
empty
(
$users
[
$uid
]))
{
...
...
@@ -148,10 +148,10 @@ class HumanVerification
// Lock must be acquired within 2 seconds
$userList
=
Cache
::
get
(
$prefix
.
"."
.
$user
[
"id"
],
[]);
$userList
[
$user
[
"uid"
]]
=
$user
;
Cache
::
put
(
$prefix
.
"."
.
$user
[
"id"
],
$userList
,
now
()
->
addWeeks
(
2
)
);
\
App\CacheHelper
::
put
(
$prefix
.
"."
.
$user
[
"id"
],
$userList
,
2
*
7
*
24
*
60
*
60
);
}
public
function
removeOldUsers
(
$userList
)
public
function
removeOldUsers
(
$prefix
,
$userList
)
{
$newUserlist
=
[];
$now
=
now
();
...
...
@@ -168,10 +168,7 @@ class HumanVerification
}
if
(
$changed
)
{
// Lock must be acquired within 2 seconds
Cache
::
lock
(
$prefix
.
"."
.
$user
[
"id"
])
->
block
(
2
,
function
()
{
Cache
::
put
(
$prefix
.
"."
.
$user
[
"id"
],
$newUserlist
,
now
()
->
addWeeks
(
2
));
});
\
App\CacheHelper
::
put
(
$prefix
.
"."
.
$user
[
"id"
],
$newUserlist
,
2
*
7
*
24
*
60
*
60
);
}
return
$newUserlist
;
...
...
app/MetaGer.php
View file @
b08a0808
...
...
@@ -323,7 +323,7 @@ class MetaGer
'page'
=>
$page
,
'engines'
=>
$this
->
next
,
];
Cache
::
put
(
$this
->
getSearchUid
(),
serialize
(
$this
->
next
),
60
);
\
App\CacheHelper
::
put
(
$this
->
getSearchUid
(),
serialize
(
$this
->
next
),
60
*
60
);
}
else
{
$this
->
next
=
[];
}
...
...
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