From d83e3a0a037b9a4d40ce22c8c51932eb23963ac2 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 8 Jun 2023 17:05:36 +0200 Subject: [PATCH] chore: remove cache options Cache was not working correctly, added more complexity and actually made response times slower. Because of this, I'm removing all cache options until we figure out a better solution. Resolves https://kolaente.dev/vikunja/api/issues/1496 Resolves https://kolaente.dev/vikunja/api/issues/907 --- config.yml.sample | 10 -------- docs/content/doc/setup/config.md | 41 -------------------------------- pkg/config/config.go | 12 ---------- pkg/db/db.go | 23 ------------------ pkg/files/db.go | 6 ----- pkg/initialize/init.go | 14 ----------- pkg/models/models.go | 5 ---- pkg/modules/migration/db.go | 15 ------------ pkg/notifications/db.go | 15 ------------ pkg/user/db.go | 15 ------------ 10 files changed, 156 deletions(-) diff --git a/config.yml.sample b/config.yml.sample index 55db80fe5..159780fc8 100644 --- a/config.yml.sample +++ b/config.yml.sample @@ -91,16 +91,6 @@ database: # Enable SSL/TLS for mysql connections. Options: false, true, skip-verify, preferred tls: false -cache: - # If cache is enabled or not - enabled: false - # Cache type. Possible values are "keyvalue", "memory" or "redis". - # When choosing "keyvalue" this setting follows the one configured in the "keyvalue" section. - # When choosing "redis" you will need to configure the redis connection separately. - type: keyvalue - # When using memory this defines the maximum size an element can take - maxelementsize: 1000 - redis: # Whether to enable redis or not enabled: false diff --git a/docs/content/doc/setup/config.md b/docs/content/doc/setup/config.md index 2abcca9af..a1d5f227f 100644 --- a/docs/content/doc/setup/config.md +++ b/docs/content/doc/setup/config.md @@ -494,47 +494,6 @@ Full path: `database.tls` Environment path: `VIKUNJA_DATABASE_TLS` ---- - -## cache - - - -### enabled - -If cache is enabled or not - -Default: `false` - -Full path: `cache.enabled` - -Environment path: `VIKUNJA_CACHE_ENABLED` - - -### type - -Cache type. Possible values are "keyvalue", "memory" or "redis". -When choosing "keyvalue" this setting follows the one configured in the "keyvalue" section. -When choosing "redis" you will need to configure the redis connection separately. - -Default: `keyvalue` - -Full path: `cache.type` - -Environment path: `VIKUNJA_CACHE_TYPE` - - -### maxelementsize - -When using memory this defines the maximum size an element can take - -Default: `1000` - -Full path: `cache.maxelementsize` - -Environment path: `VIKUNJA_CACHE_MAXELEMENTSIZE` - - --- ## redis diff --git a/pkg/config/config.go b/pkg/config/config.go index 993e8a2c4..eae242ad2 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -87,10 +87,6 @@ const ( DatabaseSslRootCert Key = `database.sslrootcert` DatabaseTLS Key = `database.tls` - CacheEnabled Key = `cache.enabled` - CacheType Key = `cache.type` - CacheMaxElementSize Key = `cache.maxelementsize` - MailerEnabled Key = `mailer.enabled` MailerHost Key = `mailer.host` MailerPort Key = `mailer.port` @@ -321,10 +317,6 @@ func InitDefaultConfig() { DatabaseSslRootCert.setDefault("") DatabaseTLS.setDefault("false") - // Cacher - CacheEnabled.setDefault(false) - CacheType.setDefault("memory") - CacheMaxElementSize.setDefault(1000) // Mailer MailerEnabled.setDefault(false) MailerHost.setDefault("") @@ -425,10 +417,6 @@ func InitConfig() { log.Println("No config file found, using default or config from environment variables.") } - if CacheType.GetString() == "keyvalue" { - CacheType.Set(KeyvalueType.GetString()) - } - if RateLimitStore.GetString() == "keyvalue" { RateLimitStore.Set(KeyvalueType.GetString()) } diff --git a/pkg/db/db.go b/pkg/db/db.go index 86dcea797..a70b4b3ba 100644 --- a/pkg/db/db.go +++ b/pkg/db/db.go @@ -17,7 +17,6 @@ package db import ( - "encoding/gob" "fmt" "net/url" "os" @@ -27,9 +26,7 @@ import ( "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/log" - xrc "gitea.com/xorm/xorm-redis-cache" "xorm.io/xorm" - "xorm.io/xorm/caches" "xorm.io/xorm/names" "xorm.io/xorm/schemas" @@ -85,30 +82,10 @@ func CreateDBEngine() (engine *xorm.Engine, err error) { logger := log.NewXormLogger("") engine.SetLogger(logger) - // Cache - // We have to initialize the cache here to avoid import cycles - if config.CacheEnabled.GetBool() { - switch config.CacheType.GetString() { - case "memory": - cacher := caches.NewLRUCacher(caches.NewMemoryStore(), config.CacheMaxElementSize.GetInt()) - engine.SetDefaultCacher(cacher) - case "redis": - cacher := xrc.NewRedisCacher(config.RedisHost.GetString(), config.RedisPassword.GetString(), xrc.DEFAULT_EXPIRATION, engine.Logger()) - engine.SetDefaultCacher(cacher) - default: - log.Info("Did not find a valid cache type. Caching disabled. Please refer to the docs for poosible cache types.") - } - } - x = engine return } -// RegisterTableStructsForCache registers tables in gob encoding for redis cache -func RegisterTableStructsForCache(val interface{}) { - gob.Register(val) -} - func initMysqlEngine() (engine *xorm.Engine, err error) { // We're using utf8mb here instead of just utf8 because we want to use non-BMP characters. // See https://stackoverflow.com/a/30074553/10924593 for more info. diff --git a/pkg/files/db.go b/pkg/files/db.go index 524dd582d..ff2d8a747 100644 --- a/pkg/files/db.go +++ b/pkg/files/db.go @@ -17,7 +17,6 @@ package files import ( - "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/db" "code.vikunja.io/api/pkg/log" "xorm.io/xorm" @@ -33,11 +32,6 @@ func SetEngine() (err error) { return } - // Cache - if config.CacheEnabled.GetBool() && config.CacheType.GetString() == "redis" { - db.RegisterTableStructsForCache(GetTables()) - } - return nil } diff --git a/pkg/initialize/init.go b/pkg/initialize/init.go index 24906b9cc..e22055909 100644 --- a/pkg/initialize/init.go +++ b/pkg/initialize/init.go @@ -29,8 +29,6 @@ import ( "code.vikunja.io/api/pkg/models" "code.vikunja.io/api/pkg/modules/auth/openid" "code.vikunja.io/api/pkg/modules/keyvalue" - migrator "code.vikunja.io/api/pkg/modules/migration" - "code.vikunja.io/api/pkg/notifications" "code.vikunja.io/api/pkg/red" "code.vikunja.io/api/pkg/user" ) @@ -56,22 +54,10 @@ func InitEngines() { if err != nil { log.Fatal(err.Error()) } - err = user.InitDB() - if err != nil { - log.Fatal(err.Error()) - } err = files.SetEngine() if err != nil { log.Fatal(err.Error()) } - err = migrator.InitDB() - if err != nil { - log.Fatal(err.Error()) - } - err = notifications.InitDB() - if err != nil { - log.Fatal(err.Error()) - } } // FullInit initializes all kinds of things in the right order diff --git a/pkg/models/models.go b/pkg/models/models.go index 56186f3d3..fc1c2dcff 100644 --- a/pkg/models/models.go +++ b/pkg/models/models.go @@ -69,11 +69,6 @@ func SetEngine() (err error) { return } - // Cache - if config.CacheEnabled.GetBool() && config.CacheType.GetString() == "redis" { - db.RegisterTableStructsForCache(GetTables()) - } - return nil } diff --git a/pkg/modules/migration/db.go b/pkg/modules/migration/db.go index 2497c9bac..eb1c62630 100644 --- a/pkg/modules/migration/db.go +++ b/pkg/modules/migration/db.go @@ -16,21 +16,6 @@ package migration -import ( - "code.vikunja.io/api/pkg/config" - "code.vikunja.io/api/pkg/db" -) - -// InitDB sets up the database connection to use in this module -func InitDB() (err error) { - // Cache - if config.CacheEnabled.GetBool() && config.CacheType.GetString() == "redis" { - db.RegisterTableStructsForCache(GetTables()) - } - - return nil -} - // GetTables returns all structs which are also a table. func GetTables() []interface{} { return []interface{}{ diff --git a/pkg/notifications/db.go b/pkg/notifications/db.go index 2e7f6b0ce..1085548c7 100644 --- a/pkg/notifications/db.go +++ b/pkg/notifications/db.go @@ -16,21 +16,6 @@ package notifications -import ( - "code.vikunja.io/api/pkg/config" - "code.vikunja.io/api/pkg/db" -) - -// InitDB sets up the database connection to use in this module -func InitDB() (err error) { - // Cache - if config.CacheEnabled.GetBool() && config.CacheType.GetString() == "redis" { - db.RegisterTableStructsForCache(GetTables()) - } - - return nil -} - // GetTables returns all structs which are also a table. func GetTables() []interface{} { return []interface{}{ diff --git a/pkg/user/db.go b/pkg/user/db.go index 25fbc03d3..52f19e9a1 100644 --- a/pkg/user/db.go +++ b/pkg/user/db.go @@ -16,21 +16,6 @@ package user -import ( - "code.vikunja.io/api/pkg/config" - "code.vikunja.io/api/pkg/db" -) - -// InitDB sets up the database connection to use in this module -func InitDB() (err error) { - // Cache - if config.CacheEnabled.GetBool() && config.CacheType.GetString() == "redis" { - db.RegisterTableStructsForCache(GetTables()) - } - - return nil -} - // GetTables returns all structs which are also a table. func GetTables() []interface{} { return []interface{}{