Background processing overhead ideas
Background processing overhead ideas
Hello all,
I was hoping to start a discussion about what can be done to trim down database calls when doing background processing, in relation to the search filter. For a while now, I have considered that querying the database (default behavior) every keyup is a lot of processing/overhead.
A simple solution would be to modify the core library dataTables.js _fnFeatureHtmlFilter function to count the number of keyups and prevent the search from occurring unless some specified length (such as every 3 characters). This would look something like the following:
[code]
// Capture the number of keyups
var filter_string_length = 0;...
jqFilter.keyup( function(e) {
// Test if the filter length is less than 3 characters
if (filter_string_length < 2)
{
filter_string_length++;
return true;
}
// Test if the filter length is more than 3 characters
else
{
filter_string_length = 0;
}
// Continue searching with a minimum of 3 characters...
[/code]
This is crude and requires modifying the core functionality of the program. I think there must be a better solution.
Your thoughts/ideas?
I was hoping to start a discussion about what can be done to trim down database calls when doing background processing, in relation to the search filter. For a while now, I have considered that querying the database (default behavior) every keyup is a lot of processing/overhead.
A simple solution would be to modify the core library dataTables.js _fnFeatureHtmlFilter function to count the number of keyups and prevent the search from occurring unless some specified length (such as every 3 characters). This would look something like the following:
[code]
// Capture the number of keyups
var filter_string_length = 0;...
jqFilter.keyup( function(e) {
// Test if the filter length is less than 3 characters
if (filter_string_length < 2)
{
filter_string_length++;
return true;
}
// Test if the filter length is more than 3 characters
else
{
filter_string_length = 0;
}
// Continue searching with a minimum of 3 characters...
[/code]
This is crude and requires modifying the core functionality of the program. I think there must be a better solution.
Your thoughts/ideas?
This discussion has been closed.
Replies
I'll have to implement something like this for a project I'm working on; still haven't looked into the API yet to see if that'll mean modifying the core or not.
I use the plugin to force return pon search, no delays and the user isn't surprised with diferent behaviors for the same page when searching (one that returns fast results other that delays, because of the number of lines).
My humble opinion is that search as it is is ok, it works extremelly well for small tables, for greater ones the developer as allways the choice of using plugins
Allan
by only allowing one timer process to send to the server (previous calls are cancelled) a lot of overhead is avoided.
[code]
// singleDelay is used in event handlers to reduce number of AJAX calls
// adds a timer delay before sending AJAX. if new data is offered, that timer is cancelled
// and a new one is created
var iDelay = 600; // miliseconds to call ajax after no new activity
var inDelay = null; // timer handle
function singleDelay(x) {
if (inDelay) clearTimeout(inDelay);
inDelay = setTimeout(x, iDelay);
}
[/code]
usage: very similar to calling setTimeout(), except it limits timers to a single timer at a time
[code]
singleDelay(function() { oTable.fnFilter(value, colnum); });
[/code]
POTENTIAL WEAKNESS: you could, because of the timing issue involved, jump from one column's filter to another, and clobber the previous one, even though you intended to filter on both columns. You could fix this easily by having an array of inDelay timers, one for each sortable column, and one global one for the global sSearch
Cheers,
Greg
Allan