Skip to content

Commit 7fb3ff1

Browse files
committed
better fix for #54, geoIP cache restriction
1 parent a3f109e commit 7fb3ff1

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/DataEngines/EloquentEngine.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ public function valueList(string $key, int $limit = -1, bool $orderByAsc = false
160160
->where(function($q) {
161161
return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
162162
})
163-
// ->where('score', '>', 0)
164163
->whereNotNull('secondary_key')
165164
->orderBy('score', $orderByAsc ? 'asc' : 'desc')
166165
->when($limit > -1, function($q) use($limit) {
@@ -193,8 +192,6 @@ public function timeLeft(string $key): int
193192

194193
public function setExpiration(string $key, int $time): bool
195194
{
196-
// $time = \Carbon\Carbon::now()->addSeconds($time);
197-
198195
return $this->model->where(['primary_key' => $this->prefix.$key])
199196
->where(function($q) {
200197
return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');

src/Traits/Record.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ protected function recordPeriods($inc)
5757
*/
5858
public function getVisitorCountry()
5959
{
60+
//In case of using unsupported cache driver. Although 'country' is globally
61+
//ignored already, we can not rely on user awareness of geoIP package restriction.
62+
if (
63+
in_array(config('cache.default'), ['file', 'dynamodb', 'database']) &&
64+
is_array($geoipTags = config('geoip.cache_tags')) && count($geoipTags) > 0
65+
) {
66+
return null;
67+
}
68+
6069
return strtolower(geoip()->getLocation()->iso_code);
6170
}
6271

0 commit comments

Comments
 (0)