Faster sort function in drive

pull/1/head
yflory 5 years ago
parent e84503bd52
commit e18c224db4

@ -2762,7 +2762,7 @@ define([
}); });
if (keys.length < 2) { return keys; } if (keys.length < 2) { return keys; }
var mult = asc ? 1 : -1; var mult = asc ? 1 : -1;
var getProp = function (el, prop) { var getProp = function (el) {
if (folder && root[el] && manager.isSharedFolder(root[el])) { if (folder && root[el] && manager.isSharedFolder(root[el])) {
var title = manager.getSharedFolderData(root[el]).title || el; var title = manager.getSharedFolderData(root[el]).title || el;
return title.toLowerCase(); return title.toLowerCase();
@ -2777,13 +2777,19 @@ define([
return hrefData.type; return hrefData.type;
} }
if (prop === 'atime' || prop === 'ctime') { if (prop === 'atime' || prop === 'ctime') {
return new Date(data[prop]); return typeof(data[prop]) === "number" ? data[prop] : new Date(data[prop]);
} }
return (manager.getTitle(id) || "").toLowerCase(); return (manager.getTitle(id) || "").toLowerCase();
}; };
var props = {};
keys.forEach(function (k) {
props[k] = getProp(k);
});
keys.sort(function(a, b) { keys.sort(function(a, b) {
if (getProp(a, prop) < getProp(b, prop)) { return mult * -1; } var _a = props[a];
if (getProp(a, prop) > getProp(b, prop)) { return mult * 1; } var _b = props[b];
if (a < b) { return mult * -1; }
if (b > a) { return mult; }
return 0; return 0;
}); });
return keys; return keys;

Loading…
Cancel
Save