implemented a quick cache for flat view
This commit is contained in:
@@ -562,6 +562,29 @@ function getPageFileList(res, viewingIdx)
|
||||
$('#file_list_div').append(html)
|
||||
}
|
||||
|
||||
// wrapper function as we want to handle real DB query success, but also do the
|
||||
// same when we just use cache
|
||||
function getEntriesByIdSuccessHandler(res,pageNumber,successCallback,viewingIdx)
|
||||
{
|
||||
if( res.length != pageList.length )
|
||||
document.alert="<alert class='alert alert-warning'>WARNING: something in data has changed since viewing this page (likely someone deleted content in another view), strongly suggest a page reload to get the latest data</alert>"
|
||||
|
||||
document.entries=res;
|
||||
// cache this
|
||||
document.page[pageNumber]=res
|
||||
successCallback(res,viewingIdx)
|
||||
resetNextPrevButtons()
|
||||
// if search, disable folders
|
||||
if( OPT.search_term )
|
||||
$('#folders').prop('disabled', 'disabled').removeClass('border-info').addClass('border-secondary').removeClass('text-info').addClass('text-secondary');
|
||||
else if( document.entries.length == 0 )
|
||||
{
|
||||
html=`<span class="alert alert-danger p-2 col-auto">No files in Path</span>`
|
||||
$('#file_list_div').append(html)
|
||||
$('#figures').append(html)
|
||||
}
|
||||
}
|
||||
|
||||
// Function to get the 'page' of entry ids out of entryList
|
||||
function getPage(pageNumber, successCallback, viewingIdx=0)
|
||||
{
|
||||
@@ -579,28 +602,18 @@ function getPage(pageNumber, successCallback, viewingIdx=0)
|
||||
|
||||
// assume nothing wrong, but if the data goes odd, then this will be non-null and displayed later (cant add here, as later code does .empty() of file divs)
|
||||
document.alert=null
|
||||
// see if we can use cache, and dont reload from DB
|
||||
if( !OPT.folders && document.page.length && document.page[pageNumber] )
|
||||
{
|
||||
getEntriesByIdSuccessHandler( document.page[pageNumber], pageNumber, successCallback, viewingIdx )
|
||||
return
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
type: 'POST', url: '/get_entries_by_ids',
|
||||
data: JSON.stringify(data), contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
success: function(res) {
|
||||
if( res.length != pageList.length )
|
||||
document.alert="<alert class='alert alert-warning'>WARNING: something in data has changed since viewing this page (likely someone deleted content in another view), strongly suggest a page reload to get the latest data</alert>"
|
||||
|
||||
document.entries=res;
|
||||
successCallback(res,viewingIdx)
|
||||
resetNextPrevButtons()
|
||||
// if search, disable folders
|
||||
if( OPT.search_term )
|
||||
$('#folders').prop('disabled', 'disabled').removeClass('border-info').addClass('border-secondary').removeClass('text-info').addClass('text-secondary');
|
||||
else if( document.entries.length == 0 )
|
||||
{
|
||||
html=`<span class="alert alert-danger p-2 col-auto">No files in Path</span>`
|
||||
$('#file_list_div').append(html)
|
||||
$('#figures').append(html)
|
||||
}
|
||||
},
|
||||
success: function(res) { getEntriesByIdSuccessHandler( res, pageNumber, successCallback, viewingIdx ) },
|
||||
error: function(xhr, status, error) { console.error("Error:", error); } });
|
||||
return
|
||||
}
|
||||
@@ -824,3 +837,4 @@ $.contextMenu({
|
||||
|
||||
// finally, for files_ip/files_sp/files_rbp - set click inside document (NOT an entry) to remove seln
|
||||
$(document).on('click', function(e) { $('.highlight').removeClass('highlight') ; SetButtonState() });
|
||||
document.page=[]
|
||||
|
||||
Reference in New Issue
Block a user