Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cache in other locations #1158

Merged
merged 3 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions middlewares/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"fmt"

"memphis/conf"
"memphis/db"
"memphis/memphis_cache"
"memphis/models"

"strings"
Expand Down Expand Up @@ -143,7 +143,7 @@ func Authenticate(c *gin.Context) {
user.TenantName = strings.ToLower(user.TenantName)
}

exists, _, err := db.GetUserByUsername(username, user.TenantName)
exists, _, err := memphis_cache.GetUser(username, user.TenantName)
if err != nil {
c.AbortWithStatusJSON(500, gin.H{"message": "Server error"})
return
Expand Down
6 changes: 3 additions & 3 deletions server/memphis_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ func (umh UserMgmtHandler) AddUser(c *gin.Context) {
c.AbortWithStatusJSON(SHOWABLE_ERROR_STATUS_CODE, gin.H{"message": usernameError.Error()})
return
}
exist, _, err := db.GetUserByUsername(username, user.TenantName)
exist, _, err := memphis_cache.GetUser(username, user.TenantName)
if err != nil {
serv.Errorf("[tenant: %v][user: %v]AddUser at GetUserByUsername: User %v: %v", user.TenantName, user.Username, body.Username, err.Error())
c.AbortWithStatusJSON(500, gin.H{"message": "Server error"})
Expand Down Expand Up @@ -1419,7 +1419,7 @@ func (umh UserMgmtHandler) RemoveUser(c *gin.Context) {

SendUserDeleteCacheUpdate([]string{username}, user.TenantName)

exist, userToRemove, err := db.GetUserByUsername(username, user.TenantName)
exist, userToRemove, err := memphis_cache.GetUser(username, user.TenantName)
if err != nil {
serv.Errorf("[tenant: %v][user: %v]RemoveUser at GetUserByUsername: User %v: %v", user.TenantName, user.Username, body.Username, err.Error())
c.AbortWithStatusJSON(500, gin.H{"message": "Server error"})
Expand Down Expand Up @@ -1651,7 +1651,7 @@ func (umh UserMgmtHandler) RefreshToken(c *gin.Context) {
return
}
sendAnalytics, _ := strconv.ParseBool(systemKey.Value)
exist, user, err := db.GetUserByUsername(username, user.TenantName)
exist, user, err := memphis_cache.GetUser(username, user.TenantName)
if err != nil {
serv.Errorf("RefreshToken: User " + username + ": " + err.Error())
c.AbortWithStatusJSON(500, gin.H{"message": "Server error"})
Expand Down
4 changes: 2 additions & 2 deletions server/memphis_handlers_producers.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (s *Server) destroyProducerDirect(c *client, reply string, msg []byte) {
if username == "" {
username = dpr.Username
}
_, user, err := db.GetUserByUsername(username, dpr.TenantName)
_, user, err := memphis_cache.GetUser(username, dpr.TenantName)
if err != nil {
serv.Errorf("[tenant: %v][user: %v]destroyProducerDirect at GetUserByUsername: Producer %v at station %v: %v", dpr.TenantName, dpr.Username, name, dpr.StationName, err.Error())
}
Expand Down Expand Up @@ -387,7 +387,7 @@ func (s *Server) destroyProducerDirectV0(c *client, reply string, dpr destroyPro
if username == "" {
username = dpr.Username
}
_, user, err := db.GetUserByUsername(username, dpr.TenantName)
_, user, err := memphis_cache.GetUser(username, dpr.TenantName)
if err != nil {
serv.Errorf("[tenant: %v][user: %v]destroyProducerDirectV0 at GetUserByUsername: Producer %v at station %v: %v", dpr.TenantName, dpr.Username, name, dpr.StationName, err.Error())
}
Expand Down
9 changes: 5 additions & 4 deletions server/memphis_handlers_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"io"
"memphis/analytics"
"memphis/db"
"memphis/memphis_cache"
"memphis/models"
"memphis/utils"
"os"
Expand Down Expand Up @@ -909,9 +910,9 @@ func (s *Server) createSchemaDirect(c *client, reply string, msg []byte) {
}

func (s *Server) updateSchemaVersion(schemaID int, tenantName string, newSchemaReq CreateSchemaReq) error {
_, user, err := db.GetUserByUsername(newSchemaReq.CreatedByUsername, tenantName)
_, user, err := memphis_cache.GetUser(newSchemaReq.CreatedByUsername, tenantName)
if err != nil {
s.Errorf("[tenant: %v]updateSchemaVersion at db.GetUserByUsername: Schema %v: %v", tenantName, newSchemaReq.Name, err.Error())
s.Errorf("[tenant: %v]updateSchemaVersion at memphis_cache.GetUser: Schema %v: %v", tenantName, newSchemaReq.Name, err.Error())
return err
}

Expand Down Expand Up @@ -963,9 +964,9 @@ func (s *Server) updateSchemaVersion(schemaID int, tenantName string, newSchemaR
func (s *Server) createNewSchema(newSchemaReq CreateSchemaReq, tenantName string) error {
schemaVersionNumber := 1

_, user, err := db.GetUserByUsername(newSchemaReq.CreatedByUsername, tenantName)
_, user, err := memphis_cache.GetUser(newSchemaReq.CreatedByUsername, tenantName)
if err != nil {
s.Errorf("[tenant: %v]createNewSchema at db.GetUserByUsername: %v", tenantName, err.Error())
s.Errorf("[tenant: %v]createNewSchema at memphis_cache.GetUser: %v", tenantName, err.Error())
return err
}

Expand Down
15 changes: 8 additions & 7 deletions server/memphis_handlers_stations.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"memphis/analytics"
"memphis/db"
"memphis/memphis_cache"
"memphis/models"
"memphis/utils"
"regexp"
Expand Down Expand Up @@ -326,14 +327,14 @@ func (s *Server) createStationDirectIntern(c *client,
}
}

exist, user, err := db.GetUserByUsername(username, csr.TenantName)
exist, user, err := memphis_cache.GetUser(username, csr.TenantName)
if err != nil {
serv.Warnf("[tenant: %v][user:%v]createStationDirect at GetUserByUsername: Station %v: %v", csr.TenantName, csr.Username, csr.StationName, err.Error())
serv.Warnf("[tenant: %v][user:%v]createStationDirect at memphis_cache.GetUser: Station %v: %v", csr.TenantName, csr.Username, csr.StationName, err.Error())
respondWithErr(s.MemphisGlobalAccountString(), s, reply, err)
return
}
if !exist {
serv.Warnf("[tenant: %v][user:%v]createStationDirect at GetUserByUsername: user %v is not exists", csr.TenantName, csr.Username, csr.Username)
serv.Warnf("[tenant: %v][user:%v]createStationDirect at memphis_cache.GetUser: user %v is not exists", csr.TenantName, csr.Username, csr.Username)
respondWithErr(s.MemphisGlobalAccountString(), s, reply, err)
return
}
Expand Down Expand Up @@ -1154,9 +1155,9 @@ func (s *Server) removeStationDirectIntern(c *client,
return
}

_, user, err := db.GetUserByUsername(dsr.Username, dsr.TenantName)
_, user, err := memphis_cache.GetUser(dsr.Username, dsr.TenantName)
if err != nil {
serv.Errorf("[tenant: %v][user: %v]removeStationDirectIntern at GetUserByUsername: Station %v: %v", dsr.TenantName, dsr.Username, dsr.StationName, err.Error())
serv.Errorf("[tenant: %v][user: %v]removeStationDirectIntern at memphis_cache.GetUser: Station %v: %v", dsr.TenantName, dsr.Username, dsr.StationName, err.Error())
respondWithErr(s.MemphisGlobalAccountString(), s, reply, err)
return
}
Expand Down Expand Up @@ -1716,9 +1717,9 @@ func (s *Server) useSchemaDirect(c *client, reply string, msg []byte) {

message := fmt.Sprintf("Schema %v has been attached to station %v by user %v", schemaName, stationName.Ext(), asr.Username)
serv.Noticef("[tenant: %v][user: %v]: %v", asr.TenantName, asr.Username, message)
_, user, err := db.GetUserByUsername(asr.Username, asr.TenantName)
_, user, err := memphis_cache.GetUser(asr.Username, asr.TenantName)
if err != nil {
serv.Errorf("[tenant: %v][user: %v]useSchemaDirect at GetUserByUsername: Schema %v at station %v: %v", asr.TenantName, asr.Username, asr.Name, asr.StationName, err.Error())
serv.Errorf("[tenant: %v][user: %v]useSchemaDirect at memphis_cache.GetUser: Schema %v at station %v: %v", asr.TenantName, asr.Username, asr.Name, asr.StationName, err.Error())
respondWithErr(s.MemphisGlobalAccountString(), s, reply, err)
return
}
Expand Down
4 changes: 2 additions & 2 deletions server/memphis_handlers_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (th TagsHandler) RemoveTag(c *gin.Context) {
message = fmt.Sprintf("Tag %v has been deleted from schema %v by user name %v", name, schema.Name, user.Username)

// case "user":
// exist, user, err := db.GetUserByUsername(body.EntityName)
// exist, user, err := memphis_cache.GetUser(body.EntityName)
// if err != nil {
// serv.Errorf("RemoveTag: Tag " + body.Name + ": " + err.Error())
// c.AbortWithStatusJSON(500, gin.H{"message": "Server error"})
Expand Down Expand Up @@ -334,7 +334,7 @@ func (th TagsHandler) UpdateTagsForEntity(c *gin.Context) {
schemaName = schema.Name

// case "user":
// exist, user, err := db.GetUserByUsername(body.EntityName)
// exist, user, err := memphis_cache.GetUser(body.EntityName)
// if err != nil {
// serv.Errorf("UpdateTagsForEntity: User " + body.EntityName + ": " + err.Error())
// c.AbortWithStatusJSON(500, gin.H{"message": "Server error"})
Expand Down