Skip to content

Commit a4f2177

Browse files
authored
fix: cache config (#446)
1 parent 746d07c commit a4f2177

File tree

7 files changed

+70
-119
lines changed

7 files changed

+70
-119
lines changed

app-modules/database-migration/src/Commands/MigrateDatabaseCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function handle(
7474
$this->info('🔄 Migrating table: '.$table);
7575

7676
if (! $isDryRun) {
77-
$migrationService->migrateTable($table, $chunkSize, function (string $processed, $total): void {
77+
$migrationService->migrateTable($table, $chunkSize, function (string $processed, int $total): void {
7878
$this->line(sprintf(' 📊 Processed %s/%s records', $processed, $total));
7979
});
8080
} else {

app-modules/database-migration/src/Services/DatabaseMigrationService.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,17 @@ class DatabaseMigrationService
2222
*/
2323
public function getSourceTables(): array
2424
{
25-
$tables = DB::connection($this->sourceConnection)
26-
->select('SHOW TABLES');
25+
$tables = DB::connection($this->sourceConnection)->select('SHOW TABLES');
2726

2827
$tableColumn = 'Tables_in_'.DB::connection($this->sourceConnection)->getDatabaseName();
2928

3029
return collect($tables)
3130
->pluck($tableColumn)
32-
->reject(fn ($table): bool => in_array($table, $this->getExcludedTables()))
31+
->reject(fn (string $table): bool => in_array($table, $this->getExcludedTables()))
3332
->values()
3433
->toArray();
3534
}
3635

37-
/**
38-
* Get the number of records in a table
39-
*/
4036
public function getTableRecordCount(string $table): int
4137
{
4238
return DB::connection($this->sourceConnection)
@@ -73,7 +69,7 @@ public function migrateTable(string $table, int $chunkSize = 1000, ?callable $pr
7369
$totalRecords,
7470
$progressCallback
7571
): void {
76-
$data = $records->map(fn ($record): array => $this->transformRecord((array) $record))->all();
72+
$data = $records->map(fn (object $record): array => $this->transformRecord((array) $record))->all();
7773

7874
DB::connection($this->targetConnection)
7975
->table($table)
@@ -170,8 +166,7 @@ private function getExcludedTables(): array
170166

171167
private function hasIdColumn(string $table): bool
172168
{
173-
return Schema::connection($this->sourceConnection)
174-
->hasColumn($table, 'id');
169+
return Schema::connection($this->sourceConnection)->hasColumn($table, 'id');
175170
}
176171

177172
/**

app/Listeners/NotifyMentionedUsers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public function handle(ReplyWasCreated $event): void
1414
{
1515
User::query()->whereIn('username', $event->reply->mentionedUsers())
1616
->get()
17-
->each(fn ($user) => $user->notify(new YouWereMentioned($event->reply)));
17+
->each(fn (User $user) => $user->notify(new YouWereMentioned($event->reply)));
1818
}
1919
}

config/cache.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
| Default Cache Store
1212
|--------------------------------------------------------------------------
1313
|
14-
| This option controls the default cache connection that gets used while
15-
| using this caching library. This connection is used when another is
16-
| not explicitly specified when executing a given caching function.
14+
| This option controls the default cache store that will be used by the
15+
| framework. This connection is utilized if another isn't explicitly
16+
| specified when running a cache operation inside the application.
1717
|
1818
*/
1919

20-
'default' => env('CACHE_DRIVER', 'file'),
20+
'default' => env('CACHE_STORE', 'database'),
2121

2222
/*
2323
|--------------------------------------------------------------------------
@@ -28,32 +28,30 @@
2828
| well as their drivers. You may even define multiple stores for the
2929
| same cache driver to group types of items stored in your caches.
3030
|
31-
| Supported drivers: "apc", "array", "database", "file",
32-
| "memcached", "redis", "dynamodb", "null"
31+
| Supported drivers: "array", "database", "file", "memcached",
32+
| "redis", "dynamodb", "octane", "null"
3333
|
3434
*/
3535

3636
'stores' => [
3737

38-
'apc' => [
39-
'driver' => 'apc',
40-
],
41-
4238
'array' => [
4339
'driver' => 'array',
4440
'serialize' => false,
4541
],
4642

4743
'database' => [
4844
'driver' => 'database',
49-
'table' => 'cache',
50-
'connection' => null,
51-
'lock_connection' => null,
45+
'connection' => env('DB_CACHE_CONNECTION'),
46+
'table' => env('DB_CACHE_TABLE', 'cache'),
47+
'lock_connection' => env('DB_CACHE_LOCK_CONNECTION'),
48+
'lock_table' => env('DB_CACHE_LOCK_TABLE'),
5249
],
5350

5451
'file' => [
5552
'driver' => 'file',
5653
'path' => storage_path('framework/cache/data'),
54+
'lock_path' => storage_path('framework/cache/data'),
5755
],
5856

5957
'memcached' => [
@@ -77,8 +75,8 @@
7775

7876
'redis' => [
7977
'driver' => 'redis',
80-
'connection' => 'cache',
81-
'lock_connection' => 'default',
78+
'connection' => env('REDIS_CACHE_CONNECTION', 'cache'),
79+
'lock_connection' => env('REDIS_CACHE_LOCK_CONNECTION', 'default'),
8280
],
8381

8482
'dynamodb' => [
@@ -90,19 +88,23 @@
9088
'endpoint' => env('DYNAMODB_ENDPOINT'),
9189
],
9290

91+
'octane' => [
92+
'driver' => 'octane',
93+
],
94+
9395
],
9496

9597
/*
9698
|--------------------------------------------------------------------------
9799
| Cache Key Prefix
98100
|--------------------------------------------------------------------------
99101
|
100-
| When utilizing a RAM based store such as APC or Memcached, there might
101-
| be other applications utilizing the same cache. So, we'll specify a
102-
| value to get prefixed to all our keys so we can avoid collisions.
102+
| When utilizing the APC, database, memcached, Redis, and DynamoDB cache
103+
| stores, there might be other applications using the same cache. For
104+
| that reason, you may prefix every cache key to avoid collisions.
103105
|
104106
*/
105107

106-
'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'),
108+
'prefix' => env('CACHE_PREFIX', Str::slug((string) env('APP_NAME', 'laravel'), '_').'_cache_'),
107109

108110
];

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,12 +1458,6 @@ parameters:
14581458
count: 1
14591459
path: config/app.php
14601460

1461-
-
1462-
rawMessage: 'Parameter #1 $title of static method Illuminate\Support\Str::slug() expects string, bool|string given.'
1463-
identifier: argument.type
1464-
count: 1
1465-
path: config/cache.php
1466-
14671461
-
14681462
rawMessage: 'Parameter #1 $title of static method Illuminate\Support\Str::slug() expects string, bool|string given.'
14691463
identifier: argument.type

phpunit.ci.xml

Lines changed: 0 additions & 49 deletions
This file was deleted.

phpunit.xml

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,45 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
3-
<testsuites>
4-
<testsuite name="Feature">
5-
<directory suffix="Test.php">./tests/Feature</directory>
6-
</testsuite>
7-
<testsuite name="Modules">
8-
<directory suffix="Test.php">./app-modules/*/tests</directory>
9-
</testsuite>
10-
</testsuites>
11-
<coverage/>
12-
<php>
13-
<env name="APP_ENV" value="testing"/>
14-
<env name="APP_KEY" value="base64:NXoQgjw2ZlOxnGbo5ZRhYgTdM6xLYsgYElNAgcTQJkE="/>
15-
<env name="APP_TIMEZONE" value="UTC"/>
16-
<env name="BCRYPT_ROUNDS" value="4"/>
17-
<env name="CACHE_DRIVER" value="array"/>
18-
<env name="DB_CONNECTION" value="pgsql"/>
19-
<env name="DB_HOST" value="pgsql"/>
20-
<env name="DB_PORT" value="5432"/>
21-
<env name="DB_DATABASE" value="testing"/>
22-
<env name="DB_USERNAME" value="sail"/>
23-
<env name="DB_PASSWORD" value="password"/>
24-
<env name="MAIL_MAILER" value="array"/>
25-
<env name="QUEUE_CONNECTION" value="sync"/>
26-
<env name="SESSION_DRIVER" value="array"/>
27-
<env name="TELESCOPE_ENABLED" value="false"/>
28-
<env name="LOG_CHANNEL" value="null"/>
29-
<env name="PEST_PARALLEL_PROCESSES" value="4"/>
30-
</php>
31-
<source>
32-
<include>
33-
<directory suffix=".php">./app</directory>
34-
</include>
35-
</source>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
cacheDirectory=".phpunit.cache"
7+
displayDetailsOnTestsThatTriggerWarnings="true"
8+
>
9+
<testsuites>
10+
<testsuite name="Feature">
11+
<directory>./tests/Feature</directory>
12+
</testsuite>
13+
<testsuite name="Modules">
14+
<directory>./app-modules/*/tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<source>
18+
<include>
19+
<directory>app</directory>
20+
<directory>app-modules</directory>
21+
</include>
22+
</source>
23+
<php>
24+
<ini name="memory_limit" value="-1"/>
25+
<env name="APP_ENV" value="testing"/>
26+
<env name="APP_KEY" value="base64:NXoQgjw2ZlOxnGbo5ZRhYgTdM6xLYsgYElNAgcTQJkE="/>
27+
<env name="APP_TIMEZONE" value="UTC"/>
28+
<env name="BCRYPT_ROUNDS" value="4"/>
29+
<env name="CACHE_STORE" value="array"/>
30+
<env name="DB_CONNECTION" value="pgsql"/>
31+
<env name="DB_HOST" value="pgsql"/>
32+
<env name="DB_PORT" value="5432"/>
33+
<env name="DB_DATABASE" value="testing"/>
34+
<env name="DB_USERNAME" value="sail"/>
35+
<env name="DB_PASSWORD" value="password"/>
36+
<env name="MAIL_MAILER" value="array"/>
37+
<env name="MEDIA_DISK" value="public"/>
38+
<env name="QUEUE_CONNECTION" value="sync"/>
39+
<env name="SESSION_DRIVER" value="array"/>
40+
<env name="PULSE_ENABLED" value="false"/>
41+
<env name="TELESCOPE_ENABLED" value="false"/>
42+
<env name="LOG_CHANNEL" value="null"/>
43+
<env name="PEST_PARALLEL_PROCESSES" value="4"/>
44+
</php>
3645
</phpunit>

0 commit comments

Comments
 (0)