KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Cache duplicates rows in datastore #286

Open Michael Wenleder opened this topic on on May 17, 2018 - 4 comments

Michael Wenleder commented on May 17, 2018

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

KoolReport commented on May 21, 2018

The way Cache package works is like this: it runs report, the data after processing will be stored in dataStores. Then those data will be saved to a file as cache. In the second load, it will detect wheter the parameters of report is changed. If it does not change, it will look for the file cache. If it found the file cache (of course within Time To Alive), it will load data in file cache instead of loading data again from databases. In other cases, Time To Alive is expired or there are changes in report parameters, it will initiate loading data again from databases.

Jesus commented on Jul 11, 2018

Hello, I am having a similar problem. When I run FileCache I am getting duplicate data. I am not changing the query nor the report parameters.

KoolReport commented on Jul 11, 2018

I see, so let me inform the dev.team to investigate the issue. I will keep you update.

Jesus commented on Jul 11, 2018

Thanks you

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

Cache