diff options
Diffstat (limited to 'db.go')
-rw-r--r-- | db.go | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -27,7 +27,7 @@ func InitDb() error { db.AutoMigrate(&DbAccountConfig{}) - db.AutoMigrate(&DbCache{}) + db.AutoMigrate(&DbKv{}) db.AutoMigrate(&DbUserMap{}) db.Model(&DbUserMap{}).AddIndex("idx_protocol_user", "protocol", "user_id") @@ -55,7 +55,7 @@ type DbAccountConfig struct { } // Long-term cache entries -type DbCache struct { +type DbKv struct { gorm.Model Key string `gorm:"unique_index"` @@ -130,27 +130,27 @@ func dbUnlockSlot(key string) { // ---- -func dbCacheGet(key string) string { - var entry DbCache - if db.Where(&DbCache{Key: key}).First(&entry).RecordNotFound() { +func dbKvGet(key string) string { + var entry DbKv + if db.Where(&DbKv{Key: key}).First(&entry).RecordNotFound() { return "" } else { return entry.Value } } -func dbCachePut(key string, value string) { - var entry DbCache - db.Where(&DbCache{Key: key}).Assign(&DbCache{Value: value}).FirstOrCreate(&entry) +func dbKvPut(key string, value string) { + var entry DbKv + db.Where(&DbKv{Key: key}).Assign(&DbKv{Value: value}).FirstOrCreate(&entry) } -func dbCacheTestAndSet(key string, value string) bool { +func dbKvTestAndSet(key string, value string) bool { dbLockSlot(key) defer dbUnlockSlot(key) // True if value was changed, false if was already set - if dbCacheGet(key) != value { - dbCachePut(key, value) + if dbKvGet(key) != value { + dbKvPut(key, value) return true } return false |