summaryrefslogtreecommitdiff
path: root/internal/config/gen/gen.go
diff options
context:
space:
mode:
authorLibravatar kim <grufwub@gmail.com>2025-05-31 17:30:57 +0200
committerLibravatar kim <gruf@noreply.codeberg.org>2025-05-31 17:30:57 +0200
commitfaed35c9388bc28ea0fdfe3aae3b489ca952c006 (patch)
tree989ab37bc3ef1b412ffc509d58939d4f1ac4f5c1 /internal/config/gen/gen.go
parent[feature] make client-side nonce calculation multi-threaded (#4219) (diff)
downloadgotosocial-faed35c9388bc28ea0fdfe3aae3b489ca952c006.tar.xz
[performance] cache mute check results (#4202)
This separates our the user mute handling from the typeconverter code, and creates a new "mutes" filter type (in a similar vein to the visibility filter) subpkg with its own result cache. This is a heavy mix of both chore given that mute calculation shouldn't have been handled in the conversion to frontend API types, and a performance bonus since we don't need to load and calculate so many things each time, just the single result each time with all necessary invalidation handled by database cache hooks. Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4202 Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/config/gen/gen.go')
-rw-r--r--internal/config/gen/gen.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/internal/config/gen/gen.go b/internal/config/gen/gen.go
index b3532caf8..faede7987 100644
--- a/internal/config/gen/gen.go
+++ b/internal/config/gen/gen.go
@@ -24,6 +24,7 @@ import (
"os"
"os/exec"
"reflect"
+ "slices"
"strings"
"time"
@@ -485,6 +486,24 @@ func generateGetSetters(out io.Writer, fields []ConfigField) {
fprintf(out, "// Set%s safely sets the value for global configuration '%s' field\n", name, field.Path)
fprintf(out, "func Set%[1]s(v %[2]s) { global.Set%[1]s(v) }\n\n", name, fieldType)
}
+
+ // Separate out the config fields (from a clone!!!) to get only the 'mem-ratio' members.
+ memFields := slices.DeleteFunc(slices.Clone(fields), func(field ConfigField) bool {
+ return !strings.Contains(field.Path, "MemRatio")
+ })
+
+ fprintf(out, "// GetTotalOfMemRatios safely fetches the combined value for all the state's mem ratio fields\n")
+ fprintf(out, "func (st *ConfigState) GetTotalOfMemRatios() (total float64) {\n")
+ fprintf(out, "\tst.mutex.RLock()\n")
+ for _, field := range memFields {
+ fprintf(out, "\ttotal += st.config.%s\n", field.Path)
+ }
+ fprintf(out, "\tst.mutex.RUnlock()\n")
+ fprintf(out, "\treturn\n")
+ fprintf(out, "}\n\n")
+
+ fprintf(out, "// GetTotalOfMemRatios safely fetches the combined value for all the global state's mem ratio fields\n")
+ fprintf(out, "func GetTotalOfMemRatios() (total float64) { return global.GetTotalOfMemRatios() }\n\n")
}
func generateMapFlattener(out io.Writer, fields []ConfigField) {