Skip to content

Commit

Permalink
fix(cache.redis): a;ways populate cached model
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Mar 10, 2021
1 parent 727159e commit 9c6a30e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ func LookupURL(shortCode string) (model.URL, int) {

data := string(line.([]uint8))

urlModel.OriginURL = data[1:]
urlModel.ShortCode = shortCode

// 0 = Inactive, 1 = Active
if data[0:1] == "0" {
return urlModel, http.StatusGone
}

urlModel.OriginURL = data[1:]
urlModel.ShortCode = shortCode

return urlModel, http.StatusFound
}

Expand All @@ -69,7 +69,10 @@ func LookupURL(shortCode string) (model.URL, int) {
func DeactivateURL(urlModel model.URL) {
cacheModel, _ := LookupURL(urlModel.ShortCode)

urlModel.OriginURL = cacheModel.OriginURL
if urlModel.OriginURL == "" {
urlModel.OriginURL = cacheModel.OriginURL
}

SavePopularURL(urlModel, true)
}

Expand Down

0 comments on commit 9c6a30e

Please sign in to comment.