-
Notifications
You must be signed in to change notification settings - Fork 3.8k
dont load templates with the same ID #6465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ import ( | |||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||
| "sort" | ||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||
| "sync" | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| "github.com/logrusorgru/aurora" | ||||||||||||||||||||||||
| "github.com/pkg/errors" | ||||||||||||||||||||||||
|
|
@@ -315,6 +316,8 @@ func (store *Store) LoadTemplatesOnlyMetadata() error { | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| templatesCache := parserItem.Cache() | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| loadedTemplateIDs := make(map[string]bool) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| for templatePath := range validPaths { | ||||||||||||||||||||||||
| template, _, _ := templatesCache.Has(templatePath) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -339,6 +342,12 @@ func (store *Store) LoadTemplatesOnlyMetadata() error { | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if template != nil { | ||||||||||||||||||||||||
| if loadedTemplateIDs[template.ID] { | ||||||||||||||||||||||||
| store.logger.Debug().Msgf("Skipping duplicate template ID '%s' from path '%s'", template.ID, templatePath) | ||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| loadedTemplateIDs[template.ID] = true | ||||||||||||||||||||||||
| template.Path = templatePath | ||||||||||||||||||||||||
| store.templates = append(store.templates, template) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
@@ -492,8 +501,20 @@ func (store *Store) LoadTemplatesWithTags(templatesList, tags []string) []*templ | |||||||||||||||||||||||
| templatePathMap := store.pathFilter.Match(includedTemplates) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| loadedTemplates := sliceutil.NewSyncSlice[*templates.Template]() | ||||||||||||||||||||||||
| loadedTemplateIDs := make(map[string]bool) | ||||||||||||||||||||||||
| var loadedTemplateIDsMutex sync.Mutex | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Mzack9999 marked this conversation as resolved.
|
||||||||||||||||||||||||
| loadTemplate := func(tmpl *templates.Template) { | ||||||||||||||||||||||||
| loadedTemplateIDsMutex.Lock() | ||||||||||||||||||||||||
| if loadedTemplateIDs[tmpl.ID] { | ||||||||||||||||||||||||
| loadedTemplateIDsMutex.Unlock() | ||||||||||||||||||||||||
| store.logger.Debug().Msgf("Skipping duplicate template ID '%s' from path '%s'", tmpl.ID, tmpl.Path) | ||||||||||||||||||||||||
| return | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| loadedTemplateIDs[tmpl.ID] = true | ||||||||||||||||||||||||
| loadedTemplateIDsMutex.Unlock() | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Comment on lines
+507
to
+513
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Make the duplicate-ID guard atomic; remove errcheck issue. Switch to LoadOrStore so only the first goroutine proceeds; others return early. This also removes the errcheck warning on Set. Apply: - if loadedTemplateIDs.Has(tmpl.ID) {
- store.logger.Debug().Msgf("Skipping duplicate template ID '%s' from path '%s'", tmpl.ID, tmpl.Path)
- return
- }
-
- loadedTemplateIDs.Set(tmpl.ID, struct{}{})
+ if _, loaded := loadedTemplateIDs.LoadOrStore(tmpl.ID, struct{}{}); loaded {
+ store.logger.Debug().Msgf("Skipping duplicate template ID '%s' from path '%s'", tmpl.ID, tmpl.Path)
+ return
+ }📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: Lint[failure] 512-512: 🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| loadedTemplates.Append(tmpl) | ||||||||||||||||||||||||
| // increment signed/unsigned counters | ||||||||||||||||||||||||
| if tmpl.Verified { | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix errcheck failure and handle Set error.
golangci-lint fails because the error return of SyncLockMap.Set is ignored. Set can return ErrReadOnly; handle it and keep behavior unchanged. (pkg.go.dev)
Apply:
📝 Committable suggestion
🧰 Tools
🪛 GitHub Check: Lint
[failure] 350-350:
Error return value of
loadedTemplateIDs.Setis not checked (errcheck)🪛 GitHub Actions: 🔨 Tests
[error] 350-350: golangci-lint: Error return value of
loadedTemplateIDs.Setis not checked (errcheck)🤖 Prompt for AI Agents