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
This commit is contained in:
parent
72e0e22152
commit
d83e3a0a03
@ -91,16 +91,6 @@ database:
|
|||||||
# Enable SSL/TLS for mysql connections. Options: false, true, skip-verify, preferred
|
# Enable SSL/TLS for mysql connections. Options: false, true, skip-verify, preferred
|
||||||
tls: false
|
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:
|
redis:
|
||||||
# Whether to enable redis or not
|
# Whether to enable redis or not
|
||||||
enabled: false
|
enabled: false
|
||||||
|
@ -494,47 +494,6 @@ Full path: `database.tls`
|
|||||||
Environment path: `VIKUNJA_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
|
## redis
|
||||||
|
@ -87,10 +87,6 @@ const (
|
|||||||
DatabaseSslRootCert Key = `database.sslrootcert`
|
DatabaseSslRootCert Key = `database.sslrootcert`
|
||||||
DatabaseTLS Key = `database.tls`
|
DatabaseTLS Key = `database.tls`
|
||||||
|
|
||||||
CacheEnabled Key = `cache.enabled`
|
|
||||||
CacheType Key = `cache.type`
|
|
||||||
CacheMaxElementSize Key = `cache.maxelementsize`
|
|
||||||
|
|
||||||
MailerEnabled Key = `mailer.enabled`
|
MailerEnabled Key = `mailer.enabled`
|
||||||
MailerHost Key = `mailer.host`
|
MailerHost Key = `mailer.host`
|
||||||
MailerPort Key = `mailer.port`
|
MailerPort Key = `mailer.port`
|
||||||
@ -321,10 +317,6 @@ func InitDefaultConfig() {
|
|||||||
DatabaseSslRootCert.setDefault("")
|
DatabaseSslRootCert.setDefault("")
|
||||||
DatabaseTLS.setDefault("false")
|
DatabaseTLS.setDefault("false")
|
||||||
|
|
||||||
// Cacher
|
|
||||||
CacheEnabled.setDefault(false)
|
|
||||||
CacheType.setDefault("memory")
|
|
||||||
CacheMaxElementSize.setDefault(1000)
|
|
||||||
// Mailer
|
// Mailer
|
||||||
MailerEnabled.setDefault(false)
|
MailerEnabled.setDefault(false)
|
||||||
MailerHost.setDefault("")
|
MailerHost.setDefault("")
|
||||||
@ -425,10 +417,6 @@ func InitConfig() {
|
|||||||
log.Println("No config file found, using default or config from environment variables.")
|
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" {
|
if RateLimitStore.GetString() == "keyvalue" {
|
||||||
RateLimitStore.Set(KeyvalueType.GetString())
|
RateLimitStore.Set(KeyvalueType.GetString())
|
||||||
}
|
}
|
||||||
|
23
pkg/db/db.go
23
pkg/db/db.go
@ -17,7 +17,6 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -27,9 +26,7 @@ import (
|
|||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
xrc "gitea.com/xorm/xorm-redis-cache"
|
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
"xorm.io/xorm/caches"
|
|
||||||
"xorm.io/xorm/names"
|
"xorm.io/xorm/names"
|
||||||
"xorm.io/xorm/schemas"
|
"xorm.io/xorm/schemas"
|
||||||
|
|
||||||
@ -85,30 +82,10 @@ func CreateDBEngine() (engine *xorm.Engine, err error) {
|
|||||||
logger := log.NewXormLogger("")
|
logger := log.NewXormLogger("")
|
||||||
engine.SetLogger(logger)
|
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
|
x = engine
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterTableStructsForCache registers tables in gob encoding for redis cache
|
|
||||||
func RegisterTableStructsForCache(val interface{}) {
|
|
||||||
gob.Register(val)
|
|
||||||
}
|
|
||||||
|
|
||||||
func initMysqlEngine() (engine *xorm.Engine, err error) {
|
func initMysqlEngine() (engine *xorm.Engine, err error) {
|
||||||
// We're using utf8mb here instead of just utf8 because we want to use non-BMP characters.
|
// 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.
|
// See https://stackoverflow.com/a/30074553/10924593 for more info.
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package files
|
package files
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/config"
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
@ -33,11 +32,6 @@ func SetEngine() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache
|
|
||||||
if config.CacheEnabled.GetBool() && config.CacheType.GetString() == "redis" {
|
|
||||||
db.RegisterTableStructsForCache(GetTables())
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,6 @@ import (
|
|||||||
"code.vikunja.io/api/pkg/models"
|
"code.vikunja.io/api/pkg/models"
|
||||||
"code.vikunja.io/api/pkg/modules/auth/openid"
|
"code.vikunja.io/api/pkg/modules/auth/openid"
|
||||||
"code.vikunja.io/api/pkg/modules/keyvalue"
|
"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/red"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
)
|
)
|
||||||
@ -56,22 +54,10 @@ func InitEngines() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
err = user.InitDB()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
err = files.SetEngine()
|
err = files.SetEngine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err.Error())
|
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
|
// FullInit initializes all kinds of things in the right order
|
||||||
|
@ -69,11 +69,6 @@ func SetEngine() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache
|
|
||||||
if config.CacheEnabled.GetBool() && config.CacheType.GetString() == "redis" {
|
|
||||||
db.RegisterTableStructsForCache(GetTables())
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,21 +16,6 @@
|
|||||||
|
|
||||||
package migration
|
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.
|
// GetTables returns all structs which are also a table.
|
||||||
func GetTables() []interface{} {
|
func GetTables() []interface{} {
|
||||||
return []interface{}{
|
return []interface{}{
|
||||||
|
@ -16,21 +16,6 @@
|
|||||||
|
|
||||||
package notifications
|
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.
|
// GetTables returns all structs which are also a table.
|
||||||
func GetTables() []interface{} {
|
func GetTables() []interface{} {
|
||||||
return []interface{}{
|
return []interface{}{
|
||||||
|
@ -16,21 +16,6 @@
|
|||||||
|
|
||||||
package user
|
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.
|
// GetTables returns all structs which are also a table.
|
||||||
func GetTables() []interface{} {
|
func GetTables() []interface{} {
|
||||||
return []interface{}{
|
return []interface{}{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user