Skip to content

Commit

Permalink
better fix for #54, geoIP cache restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
abdumu committed Sep 19, 2020
1 parent a3f109e commit 7fb3ff1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/DataEngines/EloquentEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ public function valueList(string $key, int $limit = -1, bool $orderByAsc = false
->where(function($q) {
return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
})
// ->where('score', '>', 0)
->whereNotNull('secondary_key')
->orderBy('score', $orderByAsc ? 'asc' : 'desc')
->when($limit > -1, function($q) use($limit) {
Expand Down Expand Up @@ -193,8 +192,6 @@ public function timeLeft(string $key): int

public function setExpiration(string $key, int $time): bool
{
// $time = \Carbon\Carbon::now()->addSeconds($time);

return $this->model->where(['primary_key' => $this->prefix.$key])
->where(function($q) {
return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
Expand Down
9 changes: 9 additions & 0 deletions src/Traits/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ protected function recordPeriods($inc)
*/
public function getVisitorCountry()
{
//In case of using unsupported cache driver. Although 'country' is globally
//ignored already, we can not rely on user awareness of geoIP package restriction.
if (
in_array(config('cache.default'), ['file', 'dynamodb', 'database']) &&
is_array($geoipTags = config('geoip.cache_tags')) && count($geoipTags) > 0
) {
return null;
}

return strtolower(geoip()->getLocation()->iso_code);
}

Expand Down

0 comments on commit 7fb3ff1

Please sign in to comment.