Hi team,
I do have a a database table with a lot of rows ( > 10,000). There is also two filter criteria I have (example: country, type).
I would like to load all that 10,000 rows into a node and filter them later in koolreport. Since the data is only update once a day, I thought I could make it performant using the cache.
Unfortunately I doesn't work as I expected. If I change the parameters in the view, it happens that I have duplicate values in the datastore. Is it possible to only cache the master node ($node) and clear the datastore "order_datastore" on every parameter change?
class ExampleReport extends KoolReport
{
use \koolreport\inputs\Bindable;
use \koolreport\inputs\POSTBinding;
use \koolreport\cache\FileCache;
function cacheSettings()
{
return array(
"ttl"=>3600,
);
}
protected function defaultParamValues()
{
return array(
"param1"=>null,
"param2"=>null
);
}
protected function bindParamsToInputs()
{
return array(
"param1" => "param1Selector",
"param2" => "param2Selector"
);
}
public function settings()
{
//Get default connection from config.php
$config = include "../../config.php";
return array(
"dataSources"=>array(
"example_database"=>$config["database"]
)
);
}
protected function setup()
{
if($this->params["param1"] == "") {
$this->params["param1"] = NULL;
}
if($this->params["param2"] == "") {
$this->params["param2"] = NULL;
}
$this->src('example_database')
->query("SELECT * FROM all_orders")
->saveTo($node);
if(isset($this->params["param1"]))
{
$node->pipe(new Filter(array(
array("param1","=",$this->params["param1"])
)))
->pipe($this->dataStore("order_datastore"));
}
else if(isset($this->params["param2"])) {
$node->pipe(new Filter(array(
array("param2","=",$this->params["param2"])
)))
->pipe($this->dataStore("order_datastore"));
}
else {
$node->pipe($this->dataStore('order_datastore'));
}
}
Can you show me how to do it right?
Thanks and kind regards