Problem with filters and calculated fields in repeater

Hello!

I am starting in Wix programming, so this path has presented different problems that I have not been able to solve and that is why I ask to the forum to see if someone has happened the same, could you help me.

It turns out that we have 2 databases, one contains challenges (called Desafios) that have unique values, and another database stores the data of a form where users enter challenges called to solve(called contactFormNoLabels3), users can have more one challenges.

When we start the site the home part, there is a repeater that contains data linked by formulas and by direct connection to the database. It is these data connected by a formula that is giving us problems.
When starting the website, the data connected by a formula that are companies and rise, are delayed in loading, showing inconclusive data and the appearance of the repeater without data(image 1), after one minute, it replaces the values ​​with those calculated by the function(in the code these calculations are made by function count count_companies and raise_amount(image2).

Also add that the repeater is connected to filters and after applying the filters, there are also problems with these fields linked to formulas, where they do not reload or they load very slowly, or sometimes they load by double-clicking on the filter buttons, being that they should work only by one click.

I would like to ask, if it is possible to achieve by code or our code, that a field calculated by the repeater loads faster and does not show blank values ​​and how can the buttons be improved so that do not delete the calculated field that was connected to the repeats.

Hope for your responses thanks!!

//Here is the code
// For full API documentation, including code examples, visit https://wix.to/94BuAAs
import wixData from 'wix-data';
//FILTER
export function searchButton_onClick(event) {
  $w("#text23").hide();
  let filter =  wixData.filter()  
  let searchIndustry = $w('#dropdown1').value;
  let searchperiod = $w('#region').value;
  let searchods = $w('#sdg').value;
  filter = filter.contains("contribution", searchIndustry)
  filter = filter.contains("periodOfTime", searchperiod)
  filter = filter.eq("ods", searchods)
	console.log(filter)
  $w('#dataset1').setFilter(filter)
  console.log( $w("#repeater2").data.length)
  $w("#repeater2").forEachItem( ($w, itemData, index) => {
            let color = itemData.hex;
            $w("#box13").style.backgroundColor = color;

        });
  //.eq("ods", searchods).contains("contribution", searchIndustry).contains("periodOfTime", searchperiod));
  let count = $w("#repeater2").data.length;
    	if(count === 0){
			$w("#text23").show(); $w("#text23").expand();
			
		}
		// if repeater returns no results, then show message
		else{
			$w("#text23").collapse(); $w("#text23").hide();
			}		
}



//LIGHTBOX OPEN
import wixWindow from 'wix-window';

$w.onReady(() => {

 $w("#dataset1").onReady(() => {
  $w("#repeater2").onItemReady(($item, itemData, index) => {
   $item('#container3').onClick(() => {
    let item = $item('#dataset1').getCurrentItem();
    wixWindow.openLightbox('Desafio', item)
   });
  });
 });

$w("#dataset3").onReady(() => {
  $w("#repeater1").onItemReady(($item, itemData, index) => {
   $item('#image1').onClick(() => {
    let item = $item('#dataset3').getCurrentItem();
    wixWindow.openLightbox('SDG', item)
   });
  });
 });


});

// COLOR LINE
$w.onReady(function () {
    $w("#dataset1").onReady(() => {
        $w("#repeater2").forEachItem( ($w, itemData, index) => {
            let color = itemData.hex;
            $w("#box13").style.backgroundColor = color;
            count_companies()
            raise_amount()
        });
    });
});
//COUNT COMPANIES
export function count_companies() {
            $w("#repeater2").forEachItem( ($w, itemData, index) => {
            let texting = itemData.title2;
            const filter3 = wixData.filter().contains("dropdownField", texting)
            wixData.aggregate('contactFormNoLabels3')
            .filter(filter3)
            .count()
            .run()
  .then( (results) => {
    //console.log(results.items[0].count)
	  let companies_amount = results.items[0].count
    $w('#text12').text = (companies_amount).toString();
    
  } );
        });
    }
//PERCENTAGE RAISED
export function raise_amount() {
            $w("#repeater2").forEachItem( ($w, itemData, index) => {
            let texting = itemData.title2;
            const filter2 = wixData.filter().contains("dropdownField", texting) 
            wixData.aggregate('contactFormNoLabels3') 
            .filter(filter2)
            .sum("numberField","sumamount")
			.run()
  .then( (results) => {
	  var contribution_total = results.items[0].sumamount;
	  //console.log(results.items[0].sumamount);
	  
             const filter3 = wixData.filter().contains("title2", texting)
            wixData.aggregate('Desafios')
            .filter(filter3)
            .sum("target","sumamount_target")
			.run()
  .then( (results_target) => {
	  var target_amount = results_target.items[0].sumamount_target;
    let raise_value = parseFloat(String(((contribution_total/target_amount)*100))).toFixed(0).toString() + "%"; 
    $w('#text13').text = raise_value
	  console.log(raise_value)  
          
     } );	    
  } );
        });
        }

export function clean_click(event) {
	//Add your code for this event here: 
  $w("#sdg").value = "Select State:"; 
	$w("#dropdown1").value = "Select Type:"; 
	$w("#region").value = "Select Category:";  
	$w('#text23').hide(); 
   $w("#repeater2").forEachItem( ($w, itemData, index) => {
            let color = itemData.hex;
            $w("#box13").style.backgroundColor = color;

        });
	$w("#dataset1").setFilter(wixData.filter());
}

Hey Luis,

Is this code all from one page?

I can see that you have two page onReady functions set, there should only be one. You also have a lot of code set before the first page onReady. Your code should be within or after the page onReady.

You should also a void applying data binding and code on the same element too, choose one or the other. This will improve the loading speed.

Hope this helps!

Dara | Corvid Team