Skip to content

Commit

Permalink
#837 - Bean-selection performance
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Nov 10, 2024
1 parent 0d074bc commit d95cfd2
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/app/beans/bean-modal-select/bean-modal-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export class BeanModalSelectComponent implements OnInit {

public segmentScrollHeight: string = undefined;

public uiUsedWeightCountCache: any = {};

constructor(
private readonly modalController: ModalController,
private readonly uiBeanStorage: UIBeanStorage,
Expand Down Expand Up @@ -211,18 +213,21 @@ export class BeanModalSelectComponent implements OnInit {
}

public getUsedWeightCount(_bean: Bean): number {
let usedWeightCount: number = 0;
const relatedBrews: Array<Brew> = this.uiBeanHelper.getAllBrewsForThisBean(
_bean.config.uuid
);
for (const brew of relatedBrews) {
if (brew.bean_weight_in > 0) {
usedWeightCount += brew.bean_weight_in;
} else {
usedWeightCount += brew.grind_weight;
if (this.uiUsedWeightCountCache[_bean.config.uuid] === undefined) {
let usedWeightCount: number = 0;
const relatedBrews: Array<Brew> =
this.uiBeanHelper.getAllBrewsForThisBean(_bean.config.uuid);
for (const brew of relatedBrews) {
if (brew.bean_weight_in > 0) {
usedWeightCount += brew.bean_weight_in;
} else {
usedWeightCount += brew.grind_weight;
}
}
this.uiUsedWeightCountCache[_bean.config.uuid] = usedWeightCount;
}
return usedWeightCount;
/**We cache this one, because its called many times, and its a way faster so**/
return this.uiUsedWeightCountCache[_bean.config.uuid];
}

public ngOnInit() {}
Expand Down

0 comments on commit d95cfd2

Please sign in to comment.