Problem with multiple calls on columGenerator, which uses datamanager.load

Hi Cuba Team,
I have a GroupTable with multiple generated columns.
I use a query with parameters in the xml definition with conditions which I set and then I call dataloader.load().

I also have the possibility to use the default filter component, because I want to use the pageing in the list. Everything works fine, but I have one major problem:

The column generater is called multiple times, sometimes up to x times where x is the number of rows in the result set.

this would probably not be a problem, but I fire a sql-statement in each row to get some additional data in the description of the button I generate.

Is there a way to ensure, that the button is created only once, and therefore the statement is called only once per row, or even better per visible row?

Right now, it makes the runtime unpredictable and very slow even when having not so many rows in the table.

    @NotNull
     @Install(to = "jtAdressesTable.dataInfo", subject = "columnGenerator")
     private Component  jtAdressesInfoColumnGenerator(DataTable dataTable) {
    Button btn = uiComponents.create(Button.class);
    Integer count  = 0;

     count = dataManager.loadValue(
            "select count(e) from roman_DataTable e " +
                    "where e.idMandant = :id_mandant and e.idAdresse = :id_adresse", Integer.class)
            .store(Const.dataStoreNameOracleData)
            .parameter("id_mandant", pdMandantService.getId())
            .parameter("id_adresse", dataTable.getIdAdresse())
            .one();

    String desc = count != 1 ? String.format("%s Einträge", count):String.format("%s Eintrag", count);


    btn.setCaption(desc);
    btn.setWidthFull();

    btn.addClickListener(clickEvent -> {
        openEditor(dataTable);
    });


    return btn;
}

Any help I would appreciate.

Regards
Manfred

Hi,
You can create a small cache in your screen controller to avoid calculating the same stuff several times.
Add a Map<SomeKey, Integer> countCache = new HashMap<>(); to your controller class.
And use it to remember count values between subsequent calls of the column generator.

Hi,
thanks for the tip.

I found out, that the columngenerator is called up to 8 or 10 times in subsequent filter calls.
It seems to add up sometimes for some reasons I couldn’t find out.

My workaround is to clear the DataContainer before selecting the new filtered rowset.

datasetDC.getMutableItems().clear();`
dataloader.setParameter("Param1",value1);
dataloaderDL.load();

The the columngenerator is only called once per record.

Is there any drawback when doing this?

Regards
Manfred

It is fine if it works for you.
You should just know that the Table component doesn’t maintain inside any cache of column-generated components.
So there is no guarantee it won’t call the same generator more than once for each row during the screen lifetime.