aboutsummaryrefslogtreecommitdiff
path: root/backend/cache
diff options
context:
space:
mode:
authorJacky Zhao <[email protected]>2020-05-12 23:07:47 -0700
committerGitHub <[email protected]>2020-05-12 23:07:47 -0700
commit61f5170c0c14f4994a86baac492e2625507e0d49 (patch)
tree2573730eb9b0c74cbcdab172e47eda9f6b23606a /backend/cache
parentMerge pull request #18 from jackyzha0/no-pass-rendering (diff)
parentRemove duplication (diff)
downloadctrl-v-61f5170c0c14f4994a86baac492e2625507e0d49.tar.xz
ctrl-v-61f5170c0c14f4994a86baac492e2625507e0d49.zip
Merge pull request #19 from jackyzha0/password
Check password when paste is cached
Diffstat (limited to 'backend/cache')
-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) {