Skip to content

Commit

Permalink
0.0.9 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
frikky committed Jan 27, 2021
1 parent 43aebf4 commit 6965d76
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
31 changes: 27 additions & 4 deletions db-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ import (

var err error

// Cache handlers
func DeleteCache(ctx context.Context, name string) error {
if project.Environment == "cloud" {
return memcache.Delete(ctx, name)
} else {
return errors.New(fmt.Sprintf("No cache handler for environment %s yet", project.Environment))
}

return errors.New(fmt.Sprintf("No cache found for %s", name))
}

// Cache handlers
func GetCache(ctx context.Context, name string) (interface{}, error) {
if project.Environment == "cloud" {
Expand All @@ -32,15 +43,27 @@ func GetCache(ctx context.Context, name string) (interface{}, error) {
}

func SetCache(ctx context.Context, name string, data []byte) error {
log.Printf("DATA SIZE: %d", len(data))
// Maxsize ish~

if project.Environment == "cloud" {
maxSize := 1020000
loop := false
if len(data) > maxSize {
loop = true
log.Printf("Should make multiple cache items for %s", name)
return errors.New(fmt.Sprintf("Couldn't set cache for %s - too large: %d > %d", name, len(data), maxSize))
}
_ = loop

item := &memcache.Item{
Key: name,
Value: data,
Expiration: time.Minute * 30,
}

if err := memcache.Set(ctx, item); err != nil {
log.Printf("[WARNING] Failed setting org cache: %s", err)
log.Printf("[WARNING] Failed setting cache for %s: %s", name, err)
}

return nil
Expand Down Expand Up @@ -304,7 +327,7 @@ func GetUser(ctx context.Context, username string) (*User, error) {
return curUser, nil
}
} else {
log.Printf("Failed getting cache for org: %s", err)
log.Printf("Failed getting cache for user: %s", err)
}
}

Expand All @@ -316,7 +339,7 @@ func GetUser(ctx context.Context, username string) (*User, error) {
if project.CacheDb {
data, err := json.Marshal(curUser)
if err != nil {
log.Printf("[WARNING] Failed marshalling org: %s", err)
log.Printf("[WARNING] Failed marshalling user: %s", err)
return curUser, nil
}

Expand Down Expand Up @@ -503,7 +526,7 @@ func GetAllWorkflowApps(ctx context.Context, maxLen int) ([]WorkflowApp, error)
//break
}

if len(apps) > maxLen {
if len(apps) >= maxLen {
break
}
}
Expand Down
6 changes: 4 additions & 2 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ func HandleLogout(resp http.ResponseWriter, request *http.Request) {
return
}

cacheKey := fmt.Sprintf("user_%s", strings.ToLower(userInfo.Username))
DeleteCache(ctx, cacheKey)
DeleteCache(ctx, userInfo.Session)

userInfo.Session = ""
err = SetUser(ctx, &userInfo)
if err != nil {
Expand All @@ -253,8 +257,6 @@ func HandleLogout(resp http.ResponseWriter, request *http.Request) {
return
}

//memcache.Delete(request.Context(), sessionToken)

resp.WriteHeader(200)
resp.Write([]byte(`{"success": false, "reason": "Successfully logged out"}`))
}
Expand Down

0 comments on commit 6965d76

Please sign in to comment.