<h3>{{ entry.subject or _("Paste %s") % entry.uuid }}</h3>
</div>
- {% if entry.mimetype.startswith("text/") %}
- <pre class="prettyprint linenums:4" style="min-height: 25em">{{ entry.content }}</pre>
+ {% if content %}
+ <pre class="prettyprint linenums:4" style="min-height: 25em">{{ content }}</pre>
<link rel="stylesheet" href="{{ static_url("css/prettify.css") }}">
<script src="{{ static_url("js/prettify.js") }}"></script>
ms.close()
def get(self, uuid):
- res = self.db.get("SELECT * FROM nopaste WHERE uuid = %s AND \
- (CASE WHEN time_expires IS NULL THEN TRUE ELSE NOW() < time_expires END)", uuid)
+ res = self.db.get("SELECT uuid, subject, time_created, time_expires, address, uid, \
+ mimetype, views, size FROM nopaste WHERE uuid = %s AND (CASE WHEN time_expires \
+ IS NULL THEN TRUE ELSE NOW() < time_expires END)", uuid)
if res:
- # Convert the content to a byte string
- res.content = "%s" % res.content
-
# Get the account that uploaded this if available
res.account = None
if res.uid:
return res
+ def get_content(self, uuid):
+ # Try fetching the object from memcache. If found, we return it right away.
+ content = self.memcache.get("nopaste-%s" % uuid)
+
+ # 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)
+
+ # 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)
+
+ return content
+
def _update_lastseen(self, uuid):
self.db.execute("UPDATE nopaste SET time_lastseen = NOW(), views = views + 1 \
WHERE uuid = %s", uuid)
self.set_header("Content-Type", entry.mimetype)
# Send content
- self.finish(entry.content)
+ content = self.backend.nopaste.get_content(entry.uuid)
+ self.finish(content)
class NopasteViewHandler(BaseHandler):
if not entry:
raise tornado.web.HTTPError(404)
- self.render("nopaste/view.html", entry=entry)
+ # Fetch the content if the output should be displayed
+ if entry.mimetype.startswith("text/"):
+ content = self.backend.nopaste.get_content(entry.uuid)
+ else:
+ content = None
+
+ self.render("nopaste/view.html", entry=entry, content=content)