filter for hosts_count > 0 in software title query (#16225)

for #15964, pair programmed with @jacobshandling 
---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
This commit is contained in:
Roberto Dip 2024-01-19 15:42:42 -03:00 committed by GitHub
parent 433fe225d8
commit 4d90b8ee6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 1 deletions

1
changes/15964-software Normal file
View file

@ -0,0 +1 @@
* Fixed a bug that caused the software/titles page to error

View file

@ -184,6 +184,7 @@ JOIN software_titles_host_counts sthc ON sthc.software_title_id = st.id
%s
-- placeholder for optional extra WHERE filter
WHERE sthc.team_id = ? %s
AND sthc.hosts_count > 0
GROUP BY st.id`
cveJoinType := "LEFT"

View file

@ -215,10 +215,16 @@ func testSoftwareSyncHostsSoftwareTitles(t *testing.T, ds *Datastore) {
checkTableTotalCount(3)
// update host4 (team2), remove all software and delete team
// update host4 (team2), remove all software
software4 = []fleet.Software{}
_, err = ds.UpdateHostSoftware(ctx, host4.ID, software4)
require.NoError(t, err)
require.NoError(t, ds.ReconcileSoftwareTitles(ctx))
require.NoError(t, ds.SyncHostsSoftware(ctx, time.Now()))
require.NoError(t, ds.SyncHostsSoftwareTitles(ctx, time.Now()))
listSoftwareTitlesCheckCount(t, ds, 0, 0, team2Opts, false)
// delete team
require.NoError(t, ds.DeleteTeam(ctx, team2.ID))
// this call will remove team2 from the software host counts table