Skip to content

Commit 2adc4ff

Browse files
author
Jeremy Price
committed
Fix memory-hog query in AssetCountForSidebar middleware
https://github.com/snipe/snipe-it/pull/14702/files introduced a bug where instead of doing a quick `select count(*)` of assets, it did a `select *` of assets, moving the count from the database to the PHP process. This caused OOM issues in memory-constrained environments with lots of assets, and also presented a speed issue even when memory limited were increased. Additionally, given this populates the sidebar, this was likely an issue on every page load that included the sidebar. The fix is simply removing the `all()->`, ending up with Asset::count(), which yields the desired `select count(*)` DB query.
1 parent 46779ca commit 2adc4ff

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

app/Http/Middleware/AssetCountForSidebar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function handle($request, Closure $next)
3535
}
3636

3737
try {
38-
$total_assets = Asset::all()->count();
38+
$total_assets = Asset::count();
3939
if ($settings->show_archived_in_list != '1') {
4040
$total_assets -= Asset::Archived()->count();
4141
}

0 commit comments

Comments
 (0)