Skip to content

Commit 3f0f8ce

Browse files
committed
Apply fixes from StyleCI
1 parent ada864e commit 3f0f8ce

1 file changed

Lines changed: 49 additions & 49 deletions

File tree

framework/core/tests/integration/notification/NotificationCountPerformanceTest.php

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -82,28 +82,28 @@ protected function setUp(): void
8282
$discussions[] = [
8383
// comment_count > 0 so ScopeDiscussionVisibility doesn't hide it
8484
// from members who lack discussion.editPosts permission.
85-
'id' => $i,
86-
'title' => "Discussion $i",
87-
'created_at' => Carbon::now()->toDateTimeString(),
88-
'user_id' => 1,
89-
'first_post_id' => null,
90-
'comment_count' => 1,
91-
'is_private' => 0,
85+
'id' => $i,
86+
'title' => "Discussion $i",
87+
'created_at' => Carbon::now()->toDateTimeString(),
88+
'user_id' => 1,
89+
'first_post_id' => null,
90+
'comment_count' => 1,
91+
'is_private' => 0,
9292
'last_post_number' => 1,
9393
];
9494
}
9595

9696
$posts = [];
9797
for ($i = 1; $i <= self::SUBJECT_COUNT; $i++) {
9898
$posts[] = [
99-
'id' => $i,
99+
'id' => $i,
100100
'discussion_id' => (($i - 1) % self::SUBJECT_COUNT) + 1,
101-
'number' => $i,
102-
'created_at' => Carbon::now()->toDateTimeString(),
103-
'user_id' => 1,
104-
'type' => 'comment',
105-
'content' => '<t><p>post</p></t>',
106-
'is_private' => 0,
101+
'number' => $i,
102+
'created_at' => Carbon::now()->toDateTimeString(),
103+
'user_id' => 1,
104+
'type' => 'comment',
105+
'content' => '<t><p>post</p></t>',
106+
'is_private' => 0,
107107
];
108108
}
109109

@@ -115,7 +115,7 @@ protected function setUp(): void
115115
$this->normalUser(),
116116
],
117117
'discussions' => $discussions,
118-
'posts' => $posts,
118+
'posts' => $posts,
119119
]);
120120
}
121121

@@ -131,12 +131,12 @@ protected function setUp(): void
131131
private function seed(): void
132132
{
133133
$now = Carbon::now()->toDateTimeString();
134-
$db = $this->database();
134+
$db = $this->database();
135135

136136
// --- Target user ---
137137
$half = self::TARGET_USER_NOTIFICATIONS / 2;
138138
$this->bulkInsert($db, self::USER_ID, 'discussionRenamed', $half, self::SUBJECT_COUNT, $now);
139-
$this->bulkInsert($db, self::USER_ID, 'postMentioned', $half, self::SUBJECT_COUNT, $now);
139+
$this->bulkInsert($db, self::USER_ID, 'postMentioned', $half, self::SUBJECT_COUNT, $now);
140140

141141
// A read and a deleted row that must NOT appear in the count.
142142
$db->table('notifications')->insert([
@@ -146,7 +146,7 @@ private function seed(): void
146146

147147
// --- Noise users ---
148148
$firstNoiseId = self::USER_ID + 1;
149-
$lastNoiseId = $firstNoiseId + self::NOISE_USER_COUNT - 1;
149+
$lastNoiseId = $firstNoiseId + self::NOISE_USER_COUNT - 1;
150150

151151
$chunk = [];
152152
for ($uid = $firstNoiseId; $uid <= $lastNoiseId; $uid++) {
@@ -189,14 +189,14 @@ private function bulkInsertRows($db, int $userId, string $type, int $count, int
189189
$chunk = [];
190190
for ($i = 1; $i <= $count; $i++) {
191191
$chunk[] = [
192-
'user_id' => $userId,
192+
'user_id' => $userId,
193193
'from_user_id' => 1,
194-
'type' => $type,
195-
'subject_id' => (($i - 1) % $subjectCount) + 1,
196-
'data' => null,
197-
'created_at' => $now,
198-
'read_at' => $readAt,
199-
'is_deleted' => 0,
194+
'type' => $type,
195+
'subject_id' => (($i - 1) % $subjectCount) + 1,
196+
'data' => null,
197+
'created_at' => $now,
198+
'read_at' => $readAt,
199+
'is_deleted' => 0,
200200
];
201201
if (count($chunk) === 500) {
202202
$db->table('notifications')->insert($chunk);
@@ -218,23 +218,23 @@ private function bulkInsertRows($db, int $userId, string $type, int $count, int
218218
private function seedRealistic(): void
219219
{
220220
$now = Carbon::now()->toDateTimeString();
221-
$db = $this->database();
221+
$db = $this->database();
222222

223-
$readRows = self::TARGET_USER_NOTIFICATIONS - self::REALISTIC_UNREAD_COUNT;
223+
$readRows = self::TARGET_USER_NOTIFICATIONS - self::REALISTIC_UNREAD_COUNT;
224224
$unreadRows = self::REALISTIC_UNREAD_COUNT;
225-
$half = (int) ($unreadRows / 2);
225+
$half = (int) ($unreadRows / 2);
226226

227227
// 199,500 read notifications
228228
$this->bulkInsertRead($db, self::USER_ID, 'discussionRenamed', (int) ($readRows / 2), self::SUBJECT_COUNT, $now);
229-
$this->bulkInsertRead($db, self::USER_ID, 'postMentioned', (int) ($readRows / 2), self::SUBJECT_COUNT, $now);
229+
$this->bulkInsertRead($db, self::USER_ID, 'postMentioned', (int) ($readRows / 2), self::SUBJECT_COUNT, $now);
230230

231231
// 500 unread notifications
232-
$this->bulkInsert($db, self::USER_ID, 'discussionRenamed', $half, self::SUBJECT_COUNT, $now);
233-
$this->bulkInsert($db, self::USER_ID, 'postMentioned', $unreadRows - $half, self::SUBJECT_COUNT, $now);
232+
$this->bulkInsert($db, self::USER_ID, 'discussionRenamed', $half, self::SUBJECT_COUNT, $now);
233+
$this->bulkInsert($db, self::USER_ID, 'postMentioned', $unreadRows - $half, self::SUBJECT_COUNT, $now);
234234

235235
// Noise users (same as main seed)
236236
$firstNoiseId = self::USER_ID + 1;
237-
$lastNoiseId = $firstNoiseId + self::NOISE_USER_COUNT - 1;
237+
$lastNoiseId = $firstNoiseId + self::NOISE_USER_COUNT - 1;
238238

239239
$chunk = [];
240240
for ($uid = $firstNoiseId; $uid <= $lastNoiseId; $uid++) {
@@ -297,15 +297,15 @@ public function unread_count_benchmark(): void
297297
{
298298
$this->app();
299299
$this->seed();
300-
$user = User::find(self::USER_ID);
300+
$user = User::find(self::USER_ID);
301301
$cache = $this->app()->getContainer()->make('cache.store');
302302

303303
// Warm run to stabilise caches, then flush so the timed run hits the DB.
304304
$user->getUnreadNotificationCount();
305305
$cache->flush();
306306

307-
$start = microtime(true);
308-
$count = $user->getUnreadNotificationCount();
307+
$start = microtime(true);
308+
$count = $user->getUnreadNotificationCount();
309309
$elapsed = (microtime(true) - $start) * 1000;
310310

311311
$this->assertEquals(self::EXPECTED_COUNT, $count);
@@ -317,12 +317,12 @@ public function unread_count_benchmark(): void
317317
$queries = $this->database()->getQueryLog();
318318
$this->database()->disableQueryLog();
319319

320-
$sql = $queries[0]['query'] ?? '';
321-
$bindings = $queries[0]['bindings'] ?? [];
320+
$sql = $queries[0]['query'] ?? '';
321+
$bindings = $queries[0]['bindings'] ?? [];
322322
$totalRows = $this->database()->table('notifications')->count();
323323

324324
// Run EXPLAIN on the actual query with bindings substituted.
325-
$explain = $this->database()->select('EXPLAIN ' . $sql, $bindings);
325+
$explain = $this->database()->select('EXPLAIN '.$sql, $bindings);
326326

327327
fwrite(STDOUT, sprintf(
328328
"\n[NotificationCountPerformanceTest] unread count — user rows: %d, table total: %d: %.2f ms\n",
@@ -355,14 +355,14 @@ public function new_count_benchmark(): void
355355
{
356356
$this->app();
357357
$this->seed();
358-
$user = User::find(self::USER_ID);
358+
$user = User::find(self::USER_ID);
359359
$cache = $this->app()->getContainer()->make('cache.store');
360360

361361
$user->getNewNotificationCount();
362362
$cache->flush();
363363

364-
$start = microtime(true);
365-
$count = $user->getNewNotificationCount();
364+
$start = microtime(true);
365+
$count = $user->getNewNotificationCount();
366366
$elapsed = (microtime(true) - $start) * 1000;
367367

368368
$this->assertEquals(self::EXPECTED_COUNT, $count);
@@ -371,12 +371,12 @@ public function new_count_benchmark(): void
371371
$this->database()->enableQueryLog();
372372
$cache->flush();
373373
$user->getNewNotificationCount();
374-
$queries = $this->database()->getQueryLog();
374+
$queries = $this->database()->getQueryLog();
375375
$this->database()->disableQueryLog();
376376

377-
$sql = $queries[0]['query'] ?? '';
377+
$sql = $queries[0]['query'] ?? '';
378378
$bindings = $queries[0]['bindings'] ?? [];
379-
$explain = $this->database()->select('EXPLAIN ' . $sql, $bindings);
379+
$explain = $this->database()->select('EXPLAIN '.$sql, $bindings);
380380

381381
fwrite(STDOUT, sprintf(
382382
"\n[NotificationCountPerformanceTest] new count — user rows: %d: %.2f ms\n",
@@ -412,14 +412,14 @@ public function realistic_unread_count_benchmark(): void
412412
{
413413
$this->app();
414414
$this->seedRealistic();
415-
$user = User::find(self::USER_ID);
415+
$user = User::find(self::USER_ID);
416416
$cache = $this->app()->getContainer()->make('cache.store');
417417

418418
$user->getUnreadNotificationCount();
419419
$cache->flush();
420420

421-
$start = microtime(true);
422-
$count = $user->getUnreadNotificationCount();
421+
$start = microtime(true);
422+
$count = $user->getUnreadNotificationCount();
423423
$elapsed = (microtime(true) - $start) * 1000;
424424

425425
$this->assertEquals(self::REALISTIC_UNREAD_COUNT, $count);
@@ -430,10 +430,10 @@ public function realistic_unread_count_benchmark(): void
430430
$queries = $this->database()->getQueryLog();
431431
$this->database()->disableQueryLog();
432432

433-
$sql = $queries[0]['query'] ?? '';
433+
$sql = $queries[0]['query'] ?? '';
434434
$bindings = $queries[0]['bindings'] ?? [];
435435
$totalRows = $this->database()->table('notifications')->count();
436-
$explain = $this->database()->select('EXPLAIN ' . $sql, $bindings);
436+
$explain = $this->database()->select('EXPLAIN '.$sql, $bindings);
437437

438438
fwrite(STDOUT, sprintf(
439439
"\n[NotificationCountPerformanceTest] realistic unread count — unread: %d, user total: %d, table total: %d: %.2f ms\n",

0 commit comments

Comments
 (0)