From 9220ea44b5dd5e14f3ce3a4ae93f1b31561a93f8 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 6 May 2011 03:19:20 -0400 Subject: [PATCH] Better cache. Better gc. --- scanner/PhotoAlbum.py | 1 + web/js/010-debugger.js | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/scanner/PhotoAlbum.py b/scanner/PhotoAlbum.py index eca1a84..33ea437 100644 --- a/scanner/PhotoAlbum.py +++ b/scanner/PhotoAlbum.py @@ -146,6 +146,7 @@ class Photo(object): right = image.size[0] bottom = image.size[1] - ((image.size[1] - image.size[0]) / 2) image = image.crop((left, top, right, bottom)) + gc.collect() image.thumbnail((size, size), Image.ANTIALIAS) try: image.save(thumb_path, "JPEG") diff --git a/web/js/010-debugger.js b/web/js/010-debugger.js index ecac65a..31d3db8 100644 --- a/web/js/010-debugger.js +++ b/web/js/010-debugger.js @@ -11,19 +11,25 @@ $(document).ready(function() { return "cache/" + cachePath(path + "/" + image + "_" + suffix + ".jpg"); } function loadAlbum(path) { + if (path in album_cache) { + albumLoaded(album_cache[path]); + return; + } $.ajax({ type: "GET", url: "cache/" + path + ".json", error: function() { $(document.body).html("Couldn't fetch it."); }, - success: function(album) { - current_album = album; - if (current_image_cache != null) - showPhoto(); - else - showAlbum(); - } + success: albumLoaded }); } + function albumLoaded(album) { + album_cache[cachePath(album.path)] = album; + current_album = album; + if (current_image_cache != null) + showPhoto(); + else if (cachePath(album.path) == current_album_cache) + showAlbum(); + } function showAlbum() { $("html, body").animate({ scrollTop: 0 }, "slow"); var title = ""; @@ -73,6 +79,7 @@ $(document).ready(function() { var current_album_cache = ""; var current_image_cache = ""; var current_album = null; + var album_cache = new Array(); $(window).hashchange(function() { var new_album_cache = location.hash.substring(1); var index = new_album_cache.lastIndexOf("/");