Skip to content

Commit 538ba0f

Browse files
committed
fix: delete without condition if cache disabled
1 parent 6639f0f commit 538ba0f

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/cache/CacheHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ class CacheHandler implements CacheHandlerContract
1414
* Cache policies for the given model.
1515
*
1616
* @param Rule $model The model to cache policies for.
17-
* @return Query The cached query or a new query if caching is disabled.
17+
* @return Query|Rule The cached query if caching is disabled, or origin Rule.
1818
*/
19-
public function cachePolicies(Rule $model): Query
19+
public function cachePolicies(Rule $model): Query|Rule
2020
{
2121
if ($this->config('cache.enabled', false)) {
2222
$key = $this->config('cache.key', 'tauthz');
2323
$expire = $this->config('cache.expire', 0);
2424
return $model->cache($key, $expire);
2525
} else {
26-
return $model->newQuery();
26+
return $model;
2727
}
2828
}
2929
}

src/cache/CacheHandlerContract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88
interface CacheHandlerContract
99
{
10-
public function cachePolicies(Rule $model): Query;
10+
public function cachePolicies(Rule $model): Query|Rule;
1111
}

tests/DatabaseAdapterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,17 @@ public function testCachePolicies()
358358
$start = microtime(true);
359359
Enforcer::loadPolicy();
360360
$end = microtime(true);
361-
$timeEnabled = $end - $start;
361+
$timeDisabled = $end - $start;
362362
// time cost if cache is disabled
363363
$driver = config('tauthz.default');
364364
config(['enforcers' => [$driver => [
365-
'cache' => ['enabled' => false],
365+
'cache' => ['enabled' => true],
366366
'database' => ['rules_name' => 'rules']
367367
]]], 'tauthz');
368368
$start = microtime(true);
369369
Enforcer::loadPolicy();
370370
$end = microtime(true);
371-
$timeDisabled = $end - $start;
371+
$timeEnabled = $end - $start;
372372
// ensure time cost is not greater than time cost if cache is disabled
373373
$this->assertTrue($timeEnabled < $timeDisabled);
374374
});

0 commit comments

Comments
 (0)