Better cache. Better gc.

master
Jason A. Donenfeld 2011-05-06 03:19:20 -04:00
parent 319ac51d60
commit 9220ea44b5
2 changed files with 15 additions and 7 deletions

View File

@ -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")

View File

@ -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("/");