implemented a quick cache for flat view
This commit is contained in:
2
TODO
2
TODO
@@ -1,13 +1,11 @@
|
|||||||
###
|
###
|
||||||
#
|
#
|
||||||
#
|
|
||||||
# consider how to better version jscript - across all html files, consistently
|
# consider how to better version jscript - across all html files, consistently
|
||||||
# mtime, didnt work anyway, my phone still wont pick up the change, it was adding any ?v= changed this (once)
|
# mtime, didnt work anyway, my phone still wont pick up the change, it was adding any ?v= changed this (once)
|
||||||
#
|
#
|
||||||
# 5 think I killed pa_job_manager without passing an eid to a transform job, shouldn't crash
|
# 5 think I killed pa_job_manager without passing an eid to a transform job, shouldn't crash
|
||||||
# SHOULD JUST get AI to help clean-up and write defensive code here...
|
# SHOULD JUST get AI to help clean-up and write defensive code here...
|
||||||
#
|
#
|
||||||
# could cache getPage into document.page[x], then check if it exists, if so, don't go back to server for all the data, page[x], can just store document.entries
|
|
||||||
###
|
###
|
||||||
|
|
||||||
### major fix - go to everywhere I call GetEntries(), and redo the logic totally...
|
### major fix - go to everywhere I call GetEntries(), and redo the logic totally...
|
||||||
|
|||||||
@@ -562,6 +562,29 @@ function getPageFileList(res, viewingIdx)
|
|||||||
$('#file_list_div').append(html)
|
$('#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 to get the 'page' of entry ids out of entryList
|
||||||
function getPage(pageNumber, successCallback, viewingIdx=0)
|
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)
|
// 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
|
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({
|
$.ajax({
|
||||||
type: 'POST', url: '/get_entries_by_ids',
|
type: 'POST', url: '/get_entries_by_ids',
|
||||||
data: JSON.stringify(data), contentType: 'application/json',
|
data: JSON.stringify(data), contentType: 'application/json',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(res) {
|
success: function(res) { 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;
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function(xhr, status, error) { console.error("Error:", error); } });
|
error: function(xhr, status, error) { console.error("Error:", error); } });
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -824,3 +837,4 @@ $.contextMenu({
|
|||||||
|
|
||||||
// finally, for files_ip/files_sp/files_rbp - set click inside document (NOT an entry) to remove seln
|
// 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).on('click', function(e) { $('.highlight').removeClass('highlight') ; SetButtonState() });
|
||||||
|
document.page=[]
|
||||||
|
|||||||
Reference in New Issue
Block a user