Skip to content

Commit

Permalink
#837 - Fixing caching issues ... maybe we need to delete the caching …
Browse files Browse the repository at this point in the history
…array if its above 5000 entries?
  • Loading branch information
graphefruit committed Nov 9, 2024
1 parent 56dc810 commit f218197
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/app/dashboard/dashboard.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@
<ion-list-header>
<h4 class="ion-no-margin">{{"PAGE_HOME_LAST_BREWS" | translate}}</h4>
</ion-list-header>
<div *ngIf="getBrews()?.length == 0" class="ion-padding ion-text-center">
<div *ngIf="brews?.length == 0" class="ion-padding ion-text-center">
<div>
<ion-icon color="inactive" name="beanconqueror-cup" size="large"></ion-icon>
</div>
<div class="text-color-inactive ion-margin-top">
{{"PAGE_BREWS_NO_ENTRIES" | translate}}
</div>
</div>
<div *ngFor="let brew of getBrews()">
<div *ngFor="let brew of brews">
<brew-information [layout]="'dashboard'" (brewAction)="brewAction($event[0],$event[1])"
[brew]="brew"></brew-information>
</div>
Expand Down
20 changes: 9 additions & 11 deletions src/classes/bean/bean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { UIBeanHelper } from '../../services/uiBeanHelper';
import { Brew } from '../brew/brew';
import { UIBrewHelper } from '../../services/uiBrewHelper';
import { BEAN_FREEZING_STORAGE_ENUM } from '../../enums/beans/beanFreezingStorage';
import { Mill } from '../mill/mill';


export class Bean implements IBean {
public name: string;
Expand Down Expand Up @@ -333,30 +333,28 @@ export class Bean implements IBean {
return false;
}


public removeTempReferences() {
delete this._tempRoastingMachine;
}


private getRoastingMachineStorage(): UIRoastingMachineStorage {
let uiRoastingMachineStorage: UIRoastingMachineStorage;
uiRoastingMachineStorage = UIRoastingMachineStorage.getInstance();

return uiRoastingMachineStorage;
}

private _tempRoastingMachine: RoastingMachine = undefined;

public getRoastingMachine(): RoastingMachine {
if (
this._tempRoastingMachine === undefined ||
this._tempRoastingMachine.config.uuid !==
this.bean_roast_information.roaster_machine
) {
const iRoastingMachine: IRoastingMachine =
this.getRoastingMachineStorage().getByUUID(
this.bean_roast_information.roaster_machine
) as IRoastingMachine;
const roastingMachine: RoastingMachine = new RoastingMachine();
roastingMachine.initializeByObject(iRoastingMachine);

this._tempRoastingMachine = roastingMachine;
}
return this._tempRoastingMachine;
return roastingMachine;
}

public hasPhotos() {
Expand Down
55 changes: 33 additions & 22 deletions src/classes/brew/brew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ import { IReferenceGraph } from '../../interfaces/brew/iReferenceGraph';
import { ReferenceGraph } from './referenceGraph';
import { REFERENCE_GRAPH_TYPE } from '../../enums/brews/referenceGraphType';
import { BREW_GRAPH_TYPE } from '../../enums/brews/brewGraphType';
class BrewInstanceHelper {
constructor() {

}

public static preparations: any = {};
public static mills: any = {};
public static beans: any = {};
public static waters: any = {};
}
export class Brew implements IBrew {
public grind_size: string;
public grind_weight: number;
Expand Down Expand Up @@ -215,28 +224,30 @@ export class Brew implements IBrew {
return BREW_QUANTITY_TYPES_ENUM[this.brew_beverage_quantity_type];
}

private _tempBean: Bean = undefined;
public getBean(): Bean {
const uniqueCachingID = this.config.uuid + "-" + this.bean;
if (
this._tempBean === undefined ||
this._tempBean.config.uuid !== this.bean
BrewInstanceHelper.beans[uniqueCachingID] === undefined ||
BrewInstanceHelper.beans[uniqueCachingID].config.uuid !== this.bean
) {
const iBean: IBean = this.getBeanStorageInstance().getByUUID(
this.bean
) as IBean;
const bean: Bean = new Bean();
bean.initializeByObject(iBean);
this._tempBean = bean;
BrewInstanceHelper.beans[uniqueCachingID] = bean;

}
return this._tempBean;
return BrewInstanceHelper.beans[uniqueCachingID];
}

/**We do this, else we get called all day and have performance downtimes **/
private _tempPreparation: Preparation = undefined;

public getPreparation(): Preparation {
const uniqueCachingID = this.config.uuid + "-" + this.method_of_preparation;
if (
this._tempPreparation === undefined ||
this._tempPreparation.config.uuid !== this.method_of_preparation
BrewInstanceHelper.preparations[uniqueCachingID] === undefined ||
BrewInstanceHelper.preparations[uniqueCachingID].config.uuid !== this.method_of_preparation
) {
const iPreparation: IPreparation =
this.getPreparationStorageInstance().getByUUID(
Expand All @@ -245,45 +256,45 @@ export class Brew implements IBrew {
const preparation: Preparation = new Preparation();
preparation.initializeByObject(iPreparation);

this._tempPreparation = preparation;
BrewInstanceHelper.preparations[uniqueCachingID] = preparation;
}

return this._tempPreparation;
return BrewInstanceHelper.preparations[uniqueCachingID];
}

private _tempMill: Mill = undefined;

public getMill(): Mill {
const uniqueCachingID = this.config.uuid + "-" + this.mill;
if (
this._tempMill === undefined ||
this._tempMill.config.uuid !== this.mill
BrewInstanceHelper.mills[uniqueCachingID] === undefined ||
BrewInstanceHelper.mills[uniqueCachingID].config.uuid !== this.mill
) {
const iMill: IMill = this.getMillStorageInstance().getByUUID(
this.mill
) as IMill;
const mill: Mill = new Mill();
mill.initializeByObject(iMill);
this._tempMill = mill;
BrewInstanceHelper.mills[uniqueCachingID] = mill;
}

return this._tempMill;
return BrewInstanceHelper.mills[uniqueCachingID];
}

private _tempWater: Water = undefined;

public getWater(): Water {
const uniqueCachingID = this.config.uuid + "-" + this.water;
if (
this._tempWater === undefined ||
this._tempWater.config.uuid !== this.water
BrewInstanceHelper.waters[uniqueCachingID] === undefined ||
BrewInstanceHelper.waters[uniqueCachingID].config.uuid !== this.water
) {
const iWater: IWater = this.getWaterStorageInstance().getByUUID(
this.water
) as IWater;
const water: Water = new Water();
water.initializeByObject(iWater);

this._tempWater = water;
BrewInstanceHelper.waters[uniqueCachingID] = water;
}

return this._tempWater;
return BrewInstanceHelper.waters[uniqueCachingID];
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<ion-item [hidden]="shallFlowProfileBeHidden()" [style.order]="uiBrewHelper.fieldOrder(settings.brew_order.while.brew_time,
<ion-item [hidden]="shallFlowProfileBeHidden()" [style.order]="(settings | brewFieldOrderPipe: [settings.brew_order.while.brew_time,
data.getPreparation().brew_order.while.brew_time,
data.getPreparation().use_custom_parameters)" class="ion-padding-bottom-half" lines="none">
data.getPreparation().use_custom_parameters])" class="ion-padding-bottom-half" lines="none">
<div class="ion-text-center" style="width:100%">
<ion-chip (click)="toggleChartLines('weight')" *ngIf="
smartScaleConnected() ||
Expand Down
2 changes: 2 additions & 0 deletions src/components/brews/brew-brewing/brew-brewing.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class BrewBrewingComponent implements OnInit, AfterViewInit {
return this.choosenPreparation.tools.filter((e) => e.archived === false);
}


public async ngAfterViewInit() {
setTimeout(async () => {
// If we wouldn't wait in the timeout, the components wouldnt be existing
Expand Down Expand Up @@ -517,6 +518,7 @@ export class BrewBrewingComponent implements OnInit, AfterViewInit {
}

this.maxBrewRating = this.settings.brew_rating;
this.setChoosenPreparation();
}

public getTime(): number {
Expand Down

0 comments on commit f218197

Please sign in to comment.