Repository navigation
Backend: improve Yes/No capabilities - #5191
Conversation
| } else if strings.Contains(t, " ") { | ||
| result = false | ||
| } else { | ||
| noStrings := []string{"1", "yes", "include", "true", "positive", "please", "ano", "ja", "oui", "si", "tak", "sim", "ΠΠ°", "ya", "ΡΠ°ΠΊ"} |
There was a problem hiding this comment.
Should noStrings be yesStrings?
Since these functions are frequently called, we should consider defining this list of strings as a package variable. Then, it won't need to be created in memory each time. Additionally, we could use maps instead of slices for faster lookups:
var yesSet = map[string]struct{}{
"1": {}, "y": {}, "yes": {}, "true": {}, "include": {}, "positive": {},
"ano": {}, "ja": {}, "oui": {}, "sΓ": {}, "si": {}, "tak": {}, "sim": {}, "Π΄Π°": {}, "ya": {}, "ΡΠ°ΠΊ": {},
}
var noSet = map[string]struct{}{
"0": {}, "n": {}, "no": {}, "false": {}, "none": {}, "exclude": {}, "negative": {},
"ΕΎΓ‘dnΓ½": {}, "nej": {}, "nee": {}, "nein": {}, "non": {}, "nie": {}, "nΓ£o": {}, "Π½Π΅Ρ": {}, "tidak": {}, "Π½Ρ": {},
}|
How about we call the new package "pkg/enum"? I don't think it's a reserved word in Go and it's much less to type than "constants". |
I went with constants as that is what I already used for the SQL constants in #5190. |
|
In Go, the best practice is to always use singular package names even if a package contains multiple items (most do). This way, it's better readable when you access them e.g. "enum.SQLite" or "enum.YesSet". We can make exceptions when there's a naming conflict, e.g. with a reserved word. |
|
OK, I will update both PR's to enum from constants. |
|
package constants has been renamed to enum, and code refactored. All unit tests have passed. |
|
Thanks a lot! In the meantime, I updated the Best Practices page in our Developer Guide to include Go naming conventions, as well as new sections on Concurrency and Caching: I'll review and merge your changes as soon as possible! π |
|
Thanks a lot! I'll go ahead and merge this for final testing :) |
Signed-off-by: Michael Mayer <michael@photoprism.app>
|
Our release notes have been updated to mention this improvement: |
Signed-off-by: Michael Mayer <michael@photoprism.app>
Description
These changes improve the way PhotoPrism determines if a Yes or No has been provided in a query string.
It covers Yes and No for the following languages:
Czech, Danish, Dutch, English, French, German, Indonesian, Italian, Polish, Portuguese, Russian, Ukrainian.
Acceptance Criteria