Skip to content

Commit

Permalink
feat(service.client): lookup return flag to signify cached value
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Mar 10, 2021
1 parent 9c6a30e commit eafedea
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions service/url/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,26 @@ func CreateURLShortCode(input request.URLInput) (string, error) {

// LookupOriginURL looks up origin url from shortCode
// It returns origin url if exists and is active, http error code otherwise.
func LookupOriginURL(shortCode string) (model.URL, int) {
func LookupOriginURL(shortCode string) (model.URL, int, bool) {
var urlModel model.URL

if cacheModel, status := cache.LookupURL(shortCode); status != 0 {
return cacheModel, status
return cacheModel, status, true
}

if status := orm.Connection().Where("short_code = ?", shortCode).First(&urlModel); status.RowsAffected == 0 {
return urlModel, http.StatusNotFound
return urlModel, http.StatusNotFound, false
}

if !urlModel.IsActive() {
if !urlModel.Deleted {
cache.DeactivateURL(urlModel)
}

return urlModel, http.StatusGone
return urlModel, http.StatusGone, false
}

return urlModel, http.StatusFound
return urlModel, http.StatusFound, false
}

// IncrementHits increments hit counter for given shortCode just before serving redirection
Expand Down

0 comments on commit eafedea

Please sign in to comment.