Skip to content

Commit 06acc27

Browse files
committed
refactor(dbmem): improve deprecation filtering logic with a helper function and improve comments by adding the matching SQL logic
1 parent 12985c5 commit 06acc27

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,12 @@ func (q *FakeQuerier) getProvisionerJobsByIDsWithQueuePositionLockedGlobalQueue(
13801380
return jobs, nil
13811381
}
13821382

1383+
// isDeprecated returns true if the template is deprecated.
1384+
// A template is considered deprecated when it has a deprecation message.
1385+
func isDeprecated(template database.Template) bool {
1386+
return template.Deprecated != ""
1387+
}
1388+
13831389
func (*FakeQuerier) AcquireLock(_ context.Context, _ int64) error {
13841390
return xerrors.New("AcquireLock must only be called within a transaction")
13851391
}
@@ -13021,8 +13027,17 @@ func (q *FakeQuerier) GetAuthorizedTemplates(ctx context.Context, arg database.G
1302113027
if arg.ExactName != "" && !strings.EqualFold(template.Name, arg.ExactName) {
1302213028
continue
1302313029
}
13024-
// Check if the search query filter 'Deprecated' status matches the template's 'Deprecated' status
13025-
if arg.Deprecated.Valid && arg.Deprecated.Bool != (template.Deprecated != "") {
13030+
// Filters templates based on the search query filter 'Deprecated' status
13031+
// Matching SQL logic:
13032+
// -- Filter by deprecated
13033+
// AND CASE
13034+
// WHEN :deprecated IS NOT NULL THEN
13035+
// CASE
13036+
// WHEN :deprecated THEN deprecated != ''
13037+
// ELSE deprecated = ''
13038+
// END
13039+
// ELSE true
13040+
if arg.Deprecated.Valid && arg.Deprecated.Bool != isDeprecated(template) {
1302613041
continue
1302713042
}
1302813043
if arg.FuzzyName != "" {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy