Skip to content

Commit 2eaef04

Browse files
committed
Remove dead code
1 parent 6e54e7d commit 2eaef04

File tree

6 files changed

+32
-51
lines changed

6 files changed

+32
-51
lines changed

Diff for: src/CacheKey.php

-28
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,6 @@ protected function getValuesClause(array $where = []) : string
148148

149149
protected function getValuesFromWhere(array $where) : string
150150
{
151-
if ((new Arr)->get($where, "query")) {
152-
$prefix = $this->getCachePrefix();
153-
$subKey = (new self($this->eagerLoad, $this->model, $where["query"]))
154-
->make();
155-
$subKey = str_replace($prefix, "", $subKey);
156-
$subKey = str_replace($this->getModelSlug(), "", $subKey);
157-
$classParts = explode("\\", get_class($this->model));
158-
$subKey = strtolower(array_pop($classParts)) . $subKey;
159-
160-
return $subKey;
161-
}
162-
163151
if (is_array((new Arr)->get($where, "values"))) {
164152
return implode("_", collect($where["values"])->flatten()->toArray());
165153
}
@@ -215,18 +203,6 @@ protected function getColumnClauses(array $where) : string
215203
return "-{$where["boolean"]}_{$where["first"]}_{$where["operator"]}_{$where["second"]}";
216204
}
217205

218-
protected function getInClauses(array $where) : string
219-
{
220-
if (! in_array($where["type"], ["In"])) {
221-
return "";
222-
}
223-
224-
$this->currentBinding++;
225-
$values = $this->recursiveImplode($where["values"], "_");
226-
227-
return "-{$where["column"]}_in{$values}";
228-
}
229-
230206
protected function getInAndNotInClauses(array $where) : string
231207
{
232208
if (! in_array($where["type"], ["In", "NotIn", "InRaw"])) {
@@ -248,10 +224,6 @@ protected function recursiveImplode(array $items, string $glue = ",") : string
248224
$result = "";
249225

250226
foreach ($items as $value) {
251-
if ($value instanceof Expression) {
252-
$value = $value->getValue();
253-
}
254-
255227
if (is_string($value)) {
256228
$value = str_replace('"', '', $value);
257229
$value = explode(" ", $value);

Diff for: src/CachedBelongsToMany.php

-13
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,4 @@ class CachedBelongsToMany extends BelongsToMany
1212
use BuilderCaching;
1313
use Caching;
1414
use FiresPivotEventsTrait;
15-
16-
public function getRelation($name)
17-
{
18-
$relation = parent::getRelation($name);
19-
20-
if (! $this->isCachable()
21-
&& is_a($relation->getQuery(), self::class)
22-
) {
23-
$relation->getQuery()->disableModelCaching();
24-
}
25-
26-
return $relation;
27-
}
2815
}

Diff for: src/Traits/Buildable.php

-10
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ public function first($columns = ["*"])
6868
return parent::first($columns);
6969
}
7070

71-
if (! is_array($columns)) {
72-
$columns = [$columns];
73-
}
74-
7571
$cacheKey = $this->makeCacheKey($columns, null, "-first");
7672

7773
return $this->cachedValue(func_get_args(), $cacheKey);
@@ -167,12 +163,6 @@ protected function recursiveImplodeWithKey(array $items, string $glue = "_") : s
167163
$result = "";
168164

169165
foreach ($items as $key => $value) {
170-
if (is_array($value)) {
171-
$result .= $key . $glue . $this->recursiveImplodeWithKey($value, $glue);
172-
173-
continue;
174-
}
175-
176166
$result .= $glue . $key . $glue . $value;
177167
}
178168

Diff for: tests/Integration/CachedBuilder/DeleteTest.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration\CachedBuilder;
2+
3+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;
4+
use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase;
5+
6+
class DeleteTest extends IntegrationTestCase
7+
{
8+
public function testDecrementingInvalidatesCache()
9+
{
10+
$book = (new Book)
11+
->orderBy("id", "DESC")
12+
->first();
13+
$key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:books:genealabslaravelmodelcachingtestsfixturesbook_orderBy_id_desc-first");
14+
$tags = [
15+
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook",
16+
];
17+
18+
$beforeDeleteCachedResults = $this
19+
->cache()
20+
->tags($tags)
21+
->get($key)['value'];
22+
$book->delete();
23+
$afterDeleteCachedResults = $this
24+
->cache()
25+
->tags($tags)
26+
->get($key)['value'];
27+
28+
$this->assertEquals($beforeDeleteCachedResults->id, $book->id);
29+
$this->assertNotEquals($beforeDeleteCachedResults, $afterDeleteCachedResults);
30+
$this->assertNull($afterDeleteCachedResults);
31+
}
32+
}

Diff for: tests/database/baseline.sqlite

0 Bytes
Binary file not shown.

Diff for: tests/database/testing.sqlite

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)