* Improved performance by caching:

- The albums view is stored in memory when changing from the albums to the individual album/photo view.
- When viewing photos, the next picture in the current album is preloaded.

* Default sort order of albums is changed from new to old.

* Fixed scroll position when changing from albums to album and vice versa
This commit is contained in:
Roman 2014-09-14 14:48:12 +03:00
parent f17ee01b84
commit e9544e8f8f
13 changed files with 4473 additions and 98 deletions

View File

@ -0,0 +1,9 @@
CHANGES
* Improved performance by caching:
- The albums view is stored in memory when changing from the albums to the individual album/photo view.
- When viewing photos, the next picture in the current album is preloaded.
* Default sort order of albums is changed from new to old.
* Fixed scroll position when changing from albums to album and vice versa

View File

@ -289,6 +289,8 @@ album = {
password = "",
listed = false,
downloadable = false;
albums.refresh();
if (!visible.message()&&album.json.public==0) {
@ -300,7 +302,7 @@ album = {
else $(".message .choice input.text").hide();
});
return true;
}

View File

@ -17,69 +17,73 @@ albums = {
lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomOut");
lychee.animate(".divider", "fadeOut");
startTime = new Date().getTime();
startTime = new Date().getTime();
lychee.api("getAlbums", function(data) {
/* Smart Albums */
data.unsortedAlbum = {
id: 0,
title: "Unsorted",
sysdate: data.unsortedNum + " photos",
unsorted: 1,
thumb0: data.unsortedThumb0,
thumb1: data.unsortedThumb1,
thumb2: data.unsortedThumb2
};
data.starredAlbum = {
id: "f",
title: "Starred",
sysdate: data.starredNum + " photos",
star: 1,
thumb0: data.starredThumb0,
thumb1: data.starredThumb1,
thumb2: data.starredThumb2
};
data.publicAlbum = {
id: "s",
title: "Public",
sysdate: data.publicNum + " photos",
public: 1,
thumb0: data.publicThumb0,
thumb1: data.publicThumb1,
thumb2: data.publicThumb2
};
data.recentAlbum = {
id: "r",
title: "Recent",
sysdate: data.recentNum + " photos",
recent: 1,
thumb0: data.recentThumb0,
thumb1: data.recentThumb1,
thumb2: data.recentThumb2
};
albums.json = data;
durationTime = (new Date().getTime() - startTime);
if (durationTime>300) waitTime = 0; else waitTime = 300 - durationTime;
if (!visible.albums()&&!visible.photo()&&!visible.album()) waitTime = 0;
if (visible.album()&&lychee.content.html()==="") waitTime = 0;
setTimeout(function() {
if(this.json == null) {
lychee.api("getAlbums", function(data) {
/* Smart Albums */
data.unsortedAlbum = {
id: 0,
title: "Unsorted",
sysdate: data.unsortedNum + " photos",
unsorted: 1,
thumb0: data.unsortedThumb0,
thumb1: data.unsortedThumb1,
thumb2: data.unsortedThumb2
};
data.starredAlbum = {
id: "f",
title: "Starred",
sysdate: data.starredNum + " photos",
star: 1,
thumb0: data.starredThumb0,
thumb1: data.starredThumb1,
thumb2: data.starredThumb2
};
data.publicAlbum = {
id: "s",
title: "Public",
sysdate: data.publicNum + " photos",
public: 1,
thumb0: data.publicThumb0,
thumb1: data.publicThumb1,
thumb2: data.publicThumb2
};
data.recentAlbum = {
id: "r",
title: "Recent",
sysdate: data.recentNum + " photos",
recent: 1,
thumb0: data.recentThumb0,
thumb1: data.recentThumb1,
thumb2: data.recentThumb2
};
albums.json = data;
durationTime = (new Date().getTime() - startTime);
if (durationTime>300) waitTime = 0; else waitTime = 300 - durationTime;
if (!visible.albums()&&!visible.photo()&&!visible.album()) waitTime = 0;
if (visible.album()&&lychee.content.html()==="") waitTime = 0;
setTimeout(function() {
view.header.mode("albums");
view.albums.init();
lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomIn");
}, waitTime);
});
} else {
view.header.mode("albums");
view.albums.init();
lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomIn");
}, waitTime);
});
}
},
parse: function(album) {
@ -94,6 +98,10 @@ albums = {
if (!album.thumb2) album.thumb2 = "assets/img/no_images.svg";
}
}
},
refresh: function() {
this.json = null;
}
};

View File

@ -34,7 +34,7 @@ build = {
title = albumJSON.title,
typeThumb = "";
if (title.length>18) {
if (title != null && title.length>18) {
title = albumJSON.title.substr(0, 18) + "...";
longTitle = albumJSON.title;
}
@ -76,7 +76,7 @@ build = {
longTitle = "",
title = photoJSON.title;
if (title.length>18) {
if (title != null && title.length>18) {
title = photoJSON.title.substr(0, 18) + "...";
longTitle = photoJSON.title;
}
@ -195,8 +195,8 @@ build = {
modal += "<h1><a class='icon-lock'></a> Sign In</h1>";
modal += "<a class='close icon-remove-sign'></a>";
modal += "<div class='sign_in'>";
modal += "<input id='username' type='text' name='' value='' placeholder='username'>";
modal += "<input id='password' type='password' name='' value='' placeholder='password'>";
modal += "<input id='username' type='text' name='username' value='' placeholder='username'>";
modal += "<input id='password' type='password' name='password' value='' placeholder='password'>";
modal += "</div>";
modal += "<div id='version'>Version " + lychee.version + "<span> &#8211; <a target='_blank' href='" + lychee.updateURL + "'>Update available!</a><span></div>";
modal += "<a onclick='lychee.login()' class='button active'>Sign in</a>";

View File

@ -181,7 +181,7 @@ var lychee = {
if (albumID&&photoID) {
// Trash data
albums.json = null;
//albums.json = null;
photo.json = null;
// Show Photo
@ -190,11 +190,12 @@ var lychee = {
album.load(albumID, true);
}
photo.load(photoID, albumID);
photo.preloadNext(photoID,albumID);
} else if (albumID) {
// Trash data
albums.json = null;
//albums.json = null;
photo.json = null;
// Show Album
@ -205,7 +206,7 @@ var lychee = {
} else {
// Trash data
albums.json = null;
//albums.json = null;
album.json = null;
photo.json = null;
search.code = "";

View File

@ -5,6 +5,7 @@
* @copyright 2014 by Tobias Reich
*/
cache = null;
photo = {
json: null,
@ -48,6 +49,20 @@ photo = {
});
},
//preload the next photo for better response time
preloadNext: function(photoID) {
if(album.json &&
album.json.content &&
album.json.content[photoID] &&
album.json.content[photoID].nextPhoto!="") {
var nextPhoto = album.json.content[photoID].nextPhoto;
var url = album.json.content[nextPhoto].url;
cache = new Image();
cache.src = url;
}
},
parse: function() {
@ -296,19 +311,23 @@ photo = {
if (data!==true) lychee.error(null, params, data);
});
albums.refresh();
},
setPublic: function(photoID, e) {
var params;
if (photo.json.public==2) {
modal.show("Public Album", "This photo is located in a public album. To make this photo private or public, edit the visibility of the associated album.", [["Show Album", function() { lychee.goto(photo.json.original_album) }], ["Close", function() {}]]);
return false;
}
albums.refresh();
if (visible.photo()) {

View File

@ -10,7 +10,7 @@ view = {
header: {
show: function() {
var newMargin = -1*($("#imageview #image").height()/2)+20;
clearTimeout($(window).data("timeout"));
@ -134,15 +134,17 @@ view = {
albums.parse(albums.json.recentAlbum);
if (!lychee.publicMode) smartData = build.divider("Smart Albums") + build.album(albums.json.unsortedAlbum) + build.album(albums.json.starredAlbum) + build.album(albums.json.publicAlbum) + build.album(albums.json.recentAlbum);
/* Albums */
if (albums.json.content) {
if (!lychee.publicMode) albumsData = build.divider("Albums");
/* Albums */
if (albums.json.content) {
$.each(albums.json.content, function() {
albums.parse(this);
albumsData += build.album(this);
//display albums in reverse order
albumsData = build.album(this) + albumsData;
});
if (!lychee.publicMode) albumsData = build.divider("Albums") + albumsData;
}
if (smartData===""&&albumsData==="") {
@ -163,7 +165,7 @@ view = {
title = albums.json.content[albumID].title;
if (albums.json.content[albumID].password) prefix = "<span class='icon-lock'></span> ";
if (title.length>18) {
if (title != null && title.length>18) {
longTitle = title;
title = title.substr(0, 18) + "...";
}
@ -250,6 +252,9 @@ view = {
lychee.content.html(photosData);
$("img[data-type!='svg']").retina();
//scroll to top
$("html, body").animate({ scrollTop: 0 }, "slow");
},
@ -258,7 +263,7 @@ view = {
var longTitle = "",
title = album.json.content[photoID].title;
if (title.length>18) {
if (title != null && title.length>18) {
longTitle = title;
title = title.substr(0, 18) + "...";
}
@ -456,7 +461,7 @@ view = {
photo: function() {
lychee.imageview.html(build.imageview(photo.json, photo.isSmall(), visible.controls()));
if ((album.json&&album.json.content&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].nextPhoto==="")||lychee.viewMode) $("a#next").hide();
if ((album.json&&album.json.content&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].previousPhoto==="")||lychee.viewMode) $("a#previous").hide();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -31,7 +31,7 @@ gulp.task('view', function () {
.pipe(gulp.dest('../assets/min/'));
});
/*
gulp.task('js', function () {
gulp.src(paths.js)
@ -39,6 +39,15 @@ gulp.task('js', function () {
.pipe(plugins.uglify())
.pipe(gulp.dest('../assets/min/'));
});
*/
gulp.task('js', function () {
gulp.src(paths.js)
.pipe(plugins.concat('main.js', {newLine: "\n"}))
.pipe(gulp.dest('../assets/min/'));
});
gulp.task('css', function () {

View File

@ -9,6 +9,7 @@
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
if (!defined('LYCHEE_ACCESS_ADMIN')) exit('Error: You are not allowed to access this area!');
class Admin extends Access {
public function check($fn) {
@ -72,7 +73,6 @@ class Admin extends Access {
$album = new Album($this->database, $this->plugins, $this->settings, null);
echo json_encode($album->getAll(false));
}
private function getAlbum() {

View File

@ -8,6 +8,17 @@
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
function debug_to_console( $data ) {
if ( is_array( $data ) )
$output = "<script>console.log( 'Debug Objects: " . implode( ',', $data) . "' );</script>";
else
$output = "<script>console.log( 'Debug Objects: " . $data . "' );</script>";
echo $output;
}
class Album extends Module {
private $database = null;
@ -64,26 +75,26 @@ class Album extends Module {
switch ($this->albumIDs) {
case 'f': $return['public'] = false;
$query = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp FROM lychee_photos WHERE star = 1 " . $this->settings['sorting'];
$query = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM lychee_photos WHERE star = 1 " . $this->settings['sorting'];
break;
case 's': $return['public'] = false;
$query = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp FROM lychee_photos WHERE public = 1 " . $this->settings['sorting'];
$query = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM lychee_photos WHERE public = 1 " . $this->settings['sorting'];
break;
case 'r': $return['public'] = false;
$query = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp FROM lychee_photos WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) " . $this->settings['sorting'];
$query = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM lychee_photos WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) " . $this->settings['sorting'];
break;
case '0': $return['public'] = false;
$query = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp FROM lychee_photos WHERE album = 0 " . $this->settings['sorting'];
$query = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM lychee_photos WHERE album = 0 " . $this->settings['sorting'];
break;
default: $albums = $this->database->query("SELECT * FROM lychee_albums WHERE id = '$this->albumIDs' LIMIT 1;");
$return = $albums->fetch_assoc();
$return['sysdate'] = date('d M. Y', $return['sysstamp']);
$return['password'] = ($return['password']=='' ? false : true);
$query = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp FROM lychee_photos WHERE album = '$this->albumIDs' " . $this->settings['sorting'];
$query = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM lychee_photos WHERE album = '$this->albumIDs' " . $this->settings['sorting'];
break;
}
@ -98,6 +109,9 @@ class Album extends Module {
$photo['previousPhoto'] = $previousPhotoID;
$photo['nextPhoto'] = '';
$photo['thumbUrl'] = LYCHEE_URL_UPLOADS_THUMB . $photo['thumbUrl'];
# Parse url
$photo['url'] = LYCHEE_URL_UPLOADS_BIG . $photo['url'];
if (isset($photo['takestamp'])&&$photo['takestamp']!=='0') {
$photo['cameraDate'] = 1;
@ -192,7 +206,7 @@ class Album extends Module {
# Call plugins
$this->plugins(__METHOD__, 1, func_get_args());
return $return;
}