Closed Toreg87 closed 1 month ago
Introduction of new variable $total_assets
A new variable named $total_assets
has been added to keep track of the total assets. Currently, this variable starts off with a numeric value of 0.
Conditional Statement for show_archived_in_list
Setting
A condition has been attached such that if the show_archived_in_list
setting is not '1', the total assets count will subtract the number of archived assets. Ultimately, this will ensure that archived assets are not included in the total count unless the setting allows it.
Removal of the Original $total_assets
Assignment
There was a piece of code that assigned the $total_assets
variable with the count of real-time data (RTD) assets. This code has been removed in favor of the new assignments and conditions.
Addition of a new variable $total_rtd_sidebar
A new variable $total_rtd_sidebar
has been added to hold the dedicated count of real-time data (RTD) assets. This will allow us to separately track these specific assets.
Thanks!
@Toreg87 Thanks again for submitting this!
In the interest of being helpful, I wanted to call your attention to a follow-up PR to this one: https://github.com/snipe/snipe-it/pull/14711
tl;dr: while your fix worked, your use of all() in $total_assets = Asset::all()->count();
had the unfortunate effect of slowing down execution and using a lot of memory. The reason is because all() tells the ORM to fetch everything from the database, and then operate on it. So instead of asking the database to do the count(efficient), php was being asked to do the count, after getting ALL of the data from the database (inefficient).
Leaving out all() makes the query select count(*) from assets
, vs select * from assets
.
In general, use of all() is an anti-pattern and should only be used if absolutely necessary.
Hope this is helpful đŸ™‚
Thanks again for your contribution!
Description
The total asset count in the sidenav shows the ready to deploy count instead of the total count. Fix this by adjusting the query to all assets. Also respect the setting for archived assets. Add a default value for total assets, since we are now using the settings-variable, which is not available during the setup process.
While at it, move the block for total assets before the ready to deploy assets to match the ordering of the sidenav.
Fixes #14701
Type of change
Please delete options that are not relevant.
Checklist: