Content-Length: 304145 | pFad | https://github.com/coder/coder/commit/06acc27e053b68f10450743de362fcefd32c5373

5D refactor(dbmem): improve deprecation filtering logic with a helper fu… · coder/coder@06acc27 · GitHub
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)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/coder/coder/commit/06acc27e053b68f10450743de362fcefd32c5373

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy