]> git.ipfire.org Git - ipfire.org.git/commitdiff
nopaste: Put content in memcache only for frequently requested stuff
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 31 May 2015 11:42:19 +0000 (13:42 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 31 May 2015 11:42:19 +0000 (13:42 +0200)
webapp/backend/nopaste.py

index 7db578a3ddff3174482b1d14778e7c7cec9e08e3..af339374a7d65de23dd72ca57a7f375f0b84b916 100644 (file)
@@ -68,13 +68,15 @@ class Nopaste(Object):
 
                # If the object was not in the cache, we need to fetch it from the database.
                if not content:
-                       res = self.db.get("SELECT content FROM nopaste WHERE uuid = %s", uuid)
+                       res = self.db.get("SELECT content, views FROM nopaste WHERE uuid = %s", uuid)
 
                        # Convert the content to a byte string
                        content = "%s" % res.content
 
-                       # Save it in the cache for later
-                       self.memcache.set("nopaste-%s" % uuid, content, 6 * 3600)
+                       # Save it in the cache for later when it has been requested a couple
+                       # of times
+                       if res.views >= 5:
+                               self.memcache.set("nopaste-%s" % uuid, content, 6 * 3600)
 
                return content