aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjackyzha0 <[email protected]>2020-05-12 23:07:52 -0700
committerjackyzha0 <[email protected]>2020-05-12 23:07:52 -0700
commit2f4fd2b9f78d260c6f06099a52934267cf37d8d6 (patch)
tree61271e7f5f9a904c8f1679a2edf6c62e12225ad3
parentfix dir (diff)
parentMerge pull request #19 from jackyzha0/password (diff)
downloadctrl-v-2f4fd2b9f78d260c6f06099a52934267cf37d8d6.tar.xz
ctrl-v-2f4fd2b9f78d260c6f06099a52934267cf37d8d6.zip
Merge branch 'master' of https://github.com/jackyzha0/ctrl-v into pass-rendering
-rw-r--r--backend/cache/cache.go21
1 files changed, 11 insertions, 10 deletions
diff --git a/backend/cache/cache.go b/backend/cache/cache.go
index 56581b8..71007e5 100644
--- a/backend/cache/cache.go
+++ b/backend/cache/cache.go
@@ -28,17 +28,19 @@ func (c *Cache) Get(hash, userPassword string) (db.Paste, error) {
c.lock.RLock()
// check if hash in cache
- v, ok := c.m[hash]
+ p, ok := c.m[hash]
c.lock.RUnlock()
- if ok {
- return v, nil
- }
-
// if it doesnt, lookup from db
- p, err := db.Lookup(hash)
- if err != nil {
- return p, PasteNotFound
+ if !ok {
+ var err error
+
+ p, err = db.Lookup(hash)
+ if err != nil {
+ return db.Paste{}, PasteNotFound
+ }
+
+ c.add(p)
}
// if there is a password, check the provided one against it
@@ -49,8 +51,7 @@ func (c *Cache) Get(hash, userPassword string) (db.Paste, error) {
}
}
- c.add(p)
- return p, err
+ return p, nil
}
func (c *Cache) add(p db.Paste) {