Fix #9: Restructured a bit of the pendingItems calculation, and the query used in non-memory fetches

Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
James Ketr 2018-10-13 17:07:24 -07:00
parent 14f1051f4d
commit 54ed982a42
3 changed files with 13 additions and 15 deletions

View File

@ -773,7 +773,10 @@
triggerLoadMore: function() {
if (this.$.bottom.getBoundingClientRect().bottom < window.innerHeight + 200) {
if (this.pendingPhotos.length) {
console.log("At bottom - more items; processItems requested.");
this.async(this.processItems.bind(this));
} else {
console.log("At bottom - no more items.");
}
}
},
@ -787,12 +790,6 @@
this.triggerLoadMore();
if (this.$.bottom.getBoundingClientRect().bottom < window.innerHeight + 200) {
if (this.pendingPhotos.length) {
this.async(this.processItems.bind(this));
}
}
var headerHeight = this.$.header.offsetHeight;
var i, date = null, top = null, lowest = window.innerHeight;
@ -1053,12 +1050,9 @@
photos.forEach(function(photo) {
var year = (photo.taken || photo.modified || photo.added).replace(/^(....).*$/, "$1");
for (var i = 0; i < this.years.length; i++) {
if (this.years[i] == year) {
return;
}
if (this.years.indexOf(year) == -1) {
this.push("years", year);
}
this.push("years", year);
}.bind(this));
this.pendingPhotos = this.pendingPhotos.concat(photos);
@ -1090,6 +1084,7 @@
var photos = this.pendingPhotos.splice(0, 50);
this.notifyPath("pendingPhotos.length");
console.log(this.pendingPhotos.length + " photos remain to be converted to photo-thumbnail");
for (var i = 0; i < photos.length; i++) {
var photo = photos[i], datetime;

View File

@ -62,7 +62,7 @@ app.use(bodyParser.urlencoded({
/* Any path starting with the following won't be logged via morgan */
const logSkipPaths = new RegExp("^" + basePath + "(" + [
".*\/thumbs\/",
".*thumbs\\/",
"bower_components",
].join(")|(") + ")");
app.use(morgan('common', {

View File

@ -480,16 +480,17 @@ router.get("/*", function(req, res/*, next*/) {
if (id == -1) {
index = "";
} else {
index = "AND ((strftime('%Y-%m-%d',taken)=strftime('%Y-%m-%d',:cursor) AND photos.id<"+id+ ") OR " +
"(strftime('%m-%d',taken)=strftime('%m-%d',:cursor) AND strftime('%Y',taken)<strftime('%Y',:cursor)))";
index = "AND ((strftime('%Y-%m-%d',taken)=strftime('%Y-%m-%d',:cursor) AND photos.id<:id) OR " +
"strftime('%Y-%m-%d',taken)<strftime('%Y-%m-%d',:cursor))";
}
let path = decodeURI(req.url).replace(/\?.*$/, "").replace(/^\//, ""),
query = "SELECT photos.*,albums.path AS path FROM photos " +
"INNER JOIN albums ON (albums.id=photos.albumId AND albums.path LIKE :path) " +
"WHERE (photos.duplicate=0 AND photos.deleted=0 AND photos.scanned NOT NULL " + index + ") " +
"WHERE (photos.duplicate=0 AND photos.deleted=0 AND photos.scanned NOT NULL) " + index + " " +
"ORDER BY strftime('%Y-%m-%d',taken) DESC,id DESC LIMIT " + (limit + 1),
replacements = {
id: id,
cursor: cursor,
path: path + "%"
};
@ -510,6 +511,8 @@ router.get("/*", function(req, res/*, next*/) {
let more = photos.length > limit; /* We queried one extra item to see if there are more than LIMIT available */
// console.log("Requested " + limit + " and matched " + photos.length);
let last;
if (more) {
photos.splice(limit);