Skip to content

🚀 Complete Topic-Only Flashcard Architecture Migration & 100% Working Workflow - #3

Merged
buger merged 70 commits into
mainfrom
fix-unit-deletion-and-phpunit-warnings
Sep 24, 2025
Merged

🚀 Complete Topic-Only Flashcard Architecture Migration & 100% Working Workflow#3
buger merged 70 commits into
mainfrom
fix-unit-deletion-and-phpunit-warnings

Fix N+1 query performance issues across planning and subjects

6d9cfbb
Select commit
Loading
Failed to load commit list.
probelabs / Visor: performance succeeded Sep 24, 2025 in 5m 40s

✅ Check Passed (Warnings Found)

performance check passed. Found 4 warnings, but fail_if condition was not met.

Details

📊 Summary

  • Total Issues: 4
  • Warning Issues: 4

🐛 Issues by Category

⚡ Performance (4)

  • ⚠️ app/Http/Controllers/FlashcardController.php:1087 - After fetching a paginated list of flashcards, a second, redundant query ($topic->flashcards()->count()) is executed to get the total count. The paginator object already contains this information from its initial query, making this database call unnecessary.
  • ⚠️ app/Models/Unit.php:172 - The getProgressForChild method contains commented-out logic to fetch sessions inside a foreach loop over topics. While currently disabled, re-enabling this as-is will introduce a significant N+1 query problem, executing one query per topic.
  • ⚠️ app/Services/QualityHeuristicsService.php:165 - The validateCognitiveLoad method calls $session->subject() inside a filter callback, which is executed within a loop. This is likely to trigger lazy-loading and cause an N+1 query problem if the $sessions collection is passed without the subject relationship being eager-loaded.
  • ⚠️ app/Services/QualityHeuristicsService.php:283 - The validateSubjectDistribution method calls $session->subject() inside a foreach loop. This is likely to trigger lazy-loading and cause an N+1 query problem if the $sessions collection is passed without the subject relationship being eager-loaded.

Generated by Visor - AI-powered code review

Annotations

Check warning on line 1087 in app/Http/Controllers/FlashcardController.php

See this annotation in the file changed.

@probelabs probelabs / Visor: performance

performance Issue

After fetching a paginated list of flashcards, a second, redundant query (`$topic->flashcards()->count()`) is executed to get the total count. The paginator object already contains this information from its initial query, making this database call unnecessary.
Raw output
Remove the redundant database call by retrieving the total count directly from the paginator instance using `$flashcards->total()`.

Check warning on line 175 in app/Models/Unit.php

See this annotation in the file changed.

@probelabs probelabs / Visor: performance

performance Issue

The `getProgressForChild` method contains commented-out logic to fetch sessions inside a `foreach` loop over topics. While currently disabled, re-enabling this as-is will introduce a significant N+1 query problem, executing one query per topic.
Raw output
When this feature is implemented, refactor the logic to fetch all relevant sessions for all topics in a single query before the loop. Then, group the sessions by `topic_id` in memory to avoid multiple database calls.

Check warning on line 165 in app/Services/QualityHeuristicsService.php

See this annotation in the file changed.

@probelabs probelabs / Visor: performance

performance Issue

The `validateCognitiveLoad` method calls `$session->subject()` inside a `filter` callback, which is executed within a loop. This is likely to trigger lazy-loading and cause an N+1 query problem if the `$sessions` collection is passed without the `subject` relationship being eager-loaded.
Raw output
Ensure that any code calling this service method passes the `$sessions` collection with the `subject` relationship already eager-loaded (e.g., `Session::with('subject')->get()`).

Check warning on line 283 in app/Services/QualityHeuristicsService.php

See this annotation in the file changed.

@probelabs probelabs / Visor: performance

performance Issue

The `validateSubjectDistribution` method calls `$session->subject()` inside a `foreach` loop. This is likely to trigger lazy-loading and cause an N+1 query problem if the `$sessions` collection is passed without the `subject` relationship being eager-loaded.
Raw output
Ensure that any code calling this service method passes the `$sessions` collection with the `subject` relationship already eager-loaded (e.g., `Session::with('subject')->get()`).