The problem is that is a performance killer if it is used in a table view.
I try to build a cache for example:
Using global variables to cache the foundsets and result datasets.
- Code: Select all
/**
* @type {JSDataSet}
*
* @private
*/
var clientCache = null;
/**
* @type {JSDataSet}
*
* @private
*/
var customerCache = null;
/**
* @type {JSFoundSet}
*
* @private
*/
var clientFs = null;
/**
* @type {JSFoundSet}
*
* @private
*/
var customerFs = null;
Only load foundset if there is no cached foundset.
- Code: Select all
if ( !clientFs ) {
/** @type JSFoundSet<db:/boss_sql/mandpara> */
var fs = databaseManager.getFoundSet( 'db:/boss_sql/mandpara' );
fs.addFoundSetFilterParam( 'mandnr', '<', 100000, 'Clients without foreign vessels and seamen' );
fs.addFoundSetFilterParam( 'schiff', '=', 1, 'Clients with vessels' );
fs.loadAllRecords( );
clientFs = fs;
} else {
fs = clientFs;
}
Only load foundset if there is no cached foundset.
- Code: Select all
if ( !customerFs ) {
/** @type JSFoundSet<db:/boss_sql/kunden> */
var fs = databaseManager.getFoundSet( 'db:/boss_sql/kunden' );
fs.addFoundSetFilterParam( 'firma', '!=', '', 'nur_firmen_anzeigen' );
fs.loadAllRecords( );
customerFs = fs;
} else {
fs = customerFs;
}
Return cached result, if the result is already cached.
- Code: Select all
if ( displayValue == null ) { //field is empty
foundSet.sort( displayColumn + ' asc' );
if ( displayColumn === 'name' && clientCache ) {
return clientCache;
} else if ( displayColumn === 'firma' && customerCache ) {
return customerCache;
} else {
result = databaseManager.convertToDataSet( foundSet, [ displayColumn, realColumn ] ); //[display value, real value]
}
if ( displayColumn === 'name' ) {
clientCache = result;
} else if ( displayColumn === 'firma' ) {
customerCache = result;
}
} else if ( displayValue != null ) { //field has text
var searchText = utils.stringTrim( displayValue );
var searchArray = searchText.split( ' ' );
if ( foundSet.find( ) ) {
foundSet[ displayColumn ] = '#%' + searchArray[ 0 ] + '%';
foundSet.search( );
for ( var i = 1; i < searchArray.length; i++ ) {
if ( foundSet.find( ) ) {
foundSet[ displayColumn ] = '#%' + searchArray[ i ] + '%';
foundSet.search( false, true );
}
}
}
foundSet.sort( displayColumn + ' asc');
result = databaseManager.convertToDataSet(foundSet, [ displayColumn, realColumn ] );
}
result.removeColumn( 2 );
return result;
I would be great if someone could give me some ideas how to improve it.
See complete code at GitHub.