From: Calin Crisan Date: Mon, 18 Nov 2013 19:53:17 +0000 (+0200) Subject: optimized media list loading time X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=a14be520b5314d1ddfcde3bb9d4a73acc5a2f107;p=motioneye-debian optimized media list loading time --- diff --git a/doc/todo.txt b/doc/todo.txt index c8d562a..0a24257 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -1,6 +1,3 @@ --> optimize the media list js code: - * loading many media groups (directories) is painfully slow - * scroll event could also be optimized for speed -> make camera frames positions configurable -> add a view log functionality diff --git a/static/js/main.js b/static/js/main.js index 8e2eef3..23b8fcd 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1343,7 +1343,7 @@ function runMediaDialog(cameraId, mediaType) { return; } - /* sort and group the media */ + /* group the media */ var groups = {}; data.mediaList.forEach(function (media) { var path = media.path; @@ -1373,42 +1373,7 @@ function runMediaDialog(cameraId, mediaType) { $('div.modal-container').append(tempDiv); var height = tempDiv.height(); tempDiv.remove(); - - /* prepare the entries within each group */ - keys.forEach(function (key) { - var entries = groups[key]; - - entries.forEach(function (entry) { - var entryDiv = $('
'); - - var previewImg = $(''); - entryDiv.append(previewImg); - previewImg[0]._src = '/' + mediaType + '/' + cameraId + '/preview' + entry.path + '?height=' + height; - - var downloadButton = $('
download
'); - entryDiv.append(downloadButton); - - var nameDiv = $('
' + entry.name + '
'); - entryDiv.append(nameDiv); - - var detailsDiv = $('
'); - entryDiv.append(detailsDiv); - - downloadButton[0]._onClick = function () { - window.location.href = '/picture/' + cameraId + '/download' + entry.path; - - return false; - }; - - entryDiv[0]._onClick = function () { - var pos = entries.indexOf(entry); - runPictureDialog(entries, pos, mediaType); - }; - - entry.div = entryDiv; - }); - }); - + function showGroup(key) { if (mediaListDiv.find('img.media-list-progress').length) { return; /* already in progress of loading */ @@ -1436,13 +1401,42 @@ function runMediaDialog(cameraId, mediaType) { /* add the entries to the media list */ entries.forEach(function (entry) { var entryDiv = entry.div; - var detailsDiv = entryDiv.find('div.media-list-entry-details'); - var downloadButton = entryDiv.find('div.media-list-download-button'); + var detailsDiv = null; + + if (!entryDiv) { + entryDiv = $('
'); + + var previewImg = $(''); + entryDiv.append(previewImg); + previewImg[0]._src = '/' + mediaType + '/' + cameraId + '/preview' + entry.path + '?height=' + height; + + var downloadButton = $('
download
'); + entryDiv.append(downloadButton); + + var nameDiv = $('
' + entry.name + '
'); + entryDiv.append(nameDiv); + + detailsDiv = $('
'); + entryDiv.append(detailsDiv); + + downloadButton.click(function () { + window.location.href = '/picture/' + cameraId + '/download' + entry.path; + + return false; + }); + + entryDiv.click(function () { + var pos = entries.indexOf(entry); + runPictureDialog(entries, pos, mediaType); + }); + + entry.div = entryDiv; + } + else { + detailsDiv = entry.div.find('div.media-list-entry-details'); + } detailsDiv.html(entry.momentStr + ' | ' + entry.sizeStr); - entryDiv.unbind('click').click(entryDiv[0]._onClick); - downloadButton.click(downloadButton[0]._onClick); - mediaListDiv.append(entryDiv); });