Skip to content

Commit

Permalink
#837 - Changing back to global caching and resetting when something c…
Browse files Browse the repository at this point in the history
…hanges on the needed instances.
  • Loading branch information
graphefruit committed Nov 10, 2024
1 parent 9a3d042 commit d0cf93b
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 56 deletions.
15 changes: 15 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import { UIGraphStorage } from '../services/uiGraphStorage.service';
import { UIStorage } from '../services/uiStorage';
import { MeticulousHelpPopoverComponent } from '../popover/meticulous-help-popover/meticulous-help-popover.component';
import { SplashScreen } from '@capacitor/splash-screen';
import { BrewInstanceHelper } from '../classes/brew/brew';

declare var window;

Expand Down Expand Up @@ -652,6 +653,19 @@ export class AppComponent implements AfterViewInit {
this.__instanceAppRating();
this.__attachOnDevicePause();
this.__attachOnDeviceResume();
/**If Anything changes, we reset**/
this.uiBrewStorage.attachOnEvent().subscribe((_val) => {
BrewInstanceHelper.setEntryAmountBackToZero();
});
this.uiBeanStorage.attachOnEvent().subscribe((_val) => {
BrewInstanceHelper.setEntryAmountBackToZero();
});
this.uiPreparationStorage.attachOnEvent().subscribe((_val) => {
BrewInstanceHelper.setEntryAmountBackToZero();
});
this.uiMillStorage.attachOnEvent().subscribe((_val) => {
BrewInstanceHelper.setEntryAmountBackToZero();
});
}

private async __checkBluetoothDevices() {
Expand Down Expand Up @@ -807,6 +821,7 @@ export class AppComponent implements AfterViewInit {
);
}
}
BrewInstanceHelper.setEntryAmountBackToZero();
});
}

Expand Down
8 changes: 4 additions & 4 deletions src/app/brew/brew-detail/brew-detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ <h3>{{choosenPreparation.name}}</h3>
choosenPreparation.use_custom_parameters])" detail="true" (click)="detailBean()">
<ion-label>
<h2>{{"BREW_DATA_BEAN_TYPE" | translate}}:</h2>
<h3>{{data.getBean().name}}</h3>
<h3>{{data | brewFunctionPipe: BREW_FUNCTION_PIPE_ENUM.GET_BEAN_NAME}}</h3>
</ion-label>
</ion-item>
<ion-item *ngIf="data.getCalculatedBeanAge()>-1" [style.order]="(settings | brewFieldOrderPipe: [settings.brew_order.before.bean_type,
<ion-item *ngIf="(data | brewFunctionPipe: BREW_FUNCTION_PIPE_ENUM.GET_CALCULATED_BEAN_AGE)>-1" [style.order]="(settings | brewFieldOrderPipe: [settings.brew_order.before.bean_type,
choosenPreparation.brew_order.before.bean_type,
choosenPreparation.use_custom_parameters])">
<ion-label>
Expand All @@ -98,7 +98,7 @@ <h3>{{data | brewFunctionPipe: BREW_FUNCTION_PIPE_ENUM.GET_BREW_RATIO}}</h3>
choosenPreparation.use_custom_parameters])" detail="true" (click)="detailMill()">
<ion-label>
<h2>{{"BREW_DATA_MILL" | translate}}:</h2>
<h3>{{data.getMill().name}}</h3>
<h3>{{data | brewFunctionPipe: BREW_FUNCTION_PIPE_ENUM.GET_MILL_NAME}}</h3>
</ion-label>
</ion-item>
<ion-item *ngIf="(settings | brewFieldVisiblePipe: [settings.manage_parameters.mill_speed,
Expand Down Expand Up @@ -176,7 +176,7 @@ <h3>{{data.vessel_weight}}</h3>
choosenPreparation.use_custom_parameters])">
<ion-label>
<h2>{{"BREW_DATA_WATER" | translate}}:</h2>
<h3>{{data.getWater().name}}</h3>
<h3>{{data | brewFunctionPipe: BREW_FUNCTION_PIPE_ENUM.GET_WATER_NAME}}</h3>
</ion-label>
</ion-item>
<div class="last-item"></div>
Expand Down
6 changes: 4 additions & 2 deletions src/app/dashboard/dashboard.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ export class DashboardPage implements OnInit {
this.leftOverBeansWeight = undefined;
this.leftOverFrozenBeansWeight = undefined;
this.brews = [];

this.loadBrews();
/**Short timeout needed, else the filter pipe is not working correctly**/
setTimeout(() => {
this.loadBrews();
}, 50);
}

public async ionViewWillEnter() {
Expand Down
82 changes: 36 additions & 46 deletions src/classes/brew/brew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,21 @@ 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';
export class BrewInstanceHelper {
constructor() {}

public static preparations: any = {};
public static mills: any = {};
public static beans: any = {};
public static waters: any = {};

public static setEntryAmountBackToZero() {
this.preparations = {};
this.mills = {};
this.beans = {};
this.waters = {};
}
}
export class Brew implements IBrew {
public grind_size: string;
public grind_weight: number;
Expand Down Expand Up @@ -215,99 +229,75 @@ export class Brew implements IBrew {
return BREW_QUANTITY_TYPES_ENUM[this.brew_beverage_quantity_type];
}

private _cachingObj = {
BEAN: undefined,
MILL: undefined,
PREPARATION: undefined,
WATER: undefined,
};
public deleteCachingObjects() {
delete this._cachingObj;
}
private setCachingObj(_key: string, _value: any) {
if (this.hasOwnProperty('_cachingObj') === false) {
console.log('FCK.EMPTY');
this._cachingObj = {
BEAN: undefined,
MILL: undefined,
PREPARATION: undefined,
WATER: undefined,
};
}
this._cachingObj[_key] = _value;
}
private getCachingObj(_key: string) {
if (this.hasOwnProperty('_cachingObj') === true) {
return this._cachingObj[_key];
} else {
console.log('FCK2.EMPTY');
}
return undefined;
}

public getBean(): Bean {
const uniqueCachingID = this.config.uuid + '-' + this.bean;
if (
this._cachingObj['BEAN'] === undefined ||
this._cachingObj['BEAN'].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.setCachingObj('BEAN', bean);
BrewInstanceHelper.beans[uniqueCachingID] = bean;
}
return this.getCachingObj('BEAN');
return BrewInstanceHelper.beans[uniqueCachingID];
}

/**We do this, else we get called all day and have performance downtimes **/

public getPreparation(): Preparation {
const uniqueCachingID = this.config.uuid + '-' + this.method_of_preparation;
if (
this._cachingObj['PREPARATION'] === undefined ||
this._cachingObj['PREPARATION'].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(
this.method_of_preparation
) as IPreparation;
const preparation: Preparation = new Preparation();
preparation.initializeByObject(iPreparation);
this.setCachingObj('PREPARATION', preparation);

BrewInstanceHelper.preparations[uniqueCachingID] = preparation;
}

return this.getCachingObj('PREPARATION');
return BrewInstanceHelper.preparations[uniqueCachingID];
}

public getMill(): Mill {
const uniqueCachingID = this.config.uuid + '-' + this.mill;
if (
this._cachingObj['MILL'] === undefined ||
this._cachingObj['MILL'].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.setCachingObj('MILL', mill);
BrewInstanceHelper.mills[uniqueCachingID] = mill;
}
return this.getCachingObj('MILL');
return BrewInstanceHelper.mills[uniqueCachingID];
}

public getWater(): Water {
const uniqueCachingID = this.config.uuid + '-' + this.water;
if (
this._cachingObj['WATER'] === undefined ||
this._cachingObj['WATER'].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.setCachingObj('WATER', water);
BrewInstanceHelper.waters[uniqueCachingID] = water;
}

return this.getCachingObj('WATER');
return BrewInstanceHelper.waters[uniqueCachingID];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
preparation?.use_custom_parameters])' size='6'>
<ion-label class='card-headline'>{{ 'BREW_DATA_TIME' | translate }}</ion-label>
<br />
<ion-text>{{ brew?.getFormattedTotalCoffeeBrewTime() }}</ion-text>
<ion-text>{{brew | brewFunctionPipe: BREW_FUNCTION_PIPE_ENUM.FORMATTED_TOTAL_COFFEE_BREW_TIME}}</ion-text>
</ion-col>
<ion-col *ngIf="(brew?.grind_size != '' && (settings | brewFieldVisiblePipe: [settings.visible_list_view_parameters.grind_size,
preparation?.visible_list_view_parameters.grind_size,
Expand Down Expand Up @@ -206,7 +206,7 @@
<br />
<ion-text>{{ brew?.coffee_concentration }}</ion-text>
</ion-col>
<ion-col size='6' *ngIf='brew?.getBean()?.roastingDate && (settings | brewFieldVisiblePipe: [settings.visible_list_view_parameters.bean_age_by_brew_date,
<ion-col size='6' *ngIf='bean?.roastingDate && (settings | brewFieldVisiblePipe: [settings.visible_list_view_parameters.bean_age_by_brew_date,
preparation?.visible_list_view_parameters.bean_age_by_brew_date,
preparation?.use_custom_parameters])'>
<ion-label class='card-headline'>{{ "BREW_INFORMATION_BEAN_AGE" | translate }}</ion-label>
Expand Down
5 changes: 5 additions & 0 deletions src/enums/brews/brewFunctionPipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ export enum BREW_FUNCTION_PIPE_ENUM {
FORMATTED_TOTAL_COFFEE_FIRST_DRIP_TIME = 'FORMATTED_TOTAL_COFFEE_FIRST_DRIP_TIME',
FORMATTED_TOTAL_MILL_TIME = 'FORMATTED_TOTAL_MILL_TIME',
FORMATTED_COFFEE_BREW_TIME = 'FORMATTED_COFFEE_BREW_TIME',
FORMATTED_TOTAL_COFFEE_BREW_TIME = 'FORMATTED_TOTAL_COFFEE_BREW_TIME',
FORMATTED_BREW_TIME = 'FORMATTED_BREW_TIME',
GET_CALCULATED_BEAN_AGE = 'GET_CALCULATED_BEAN_AGE',
IS_ARCHIVED = 'IS_ARCHIVED',
GET_GRAMS_PER_LITER = 'GET_GRAMS_PER_LITER',
GET_PREPARATION_TOOL_NAME = 'GET_PREPARATION_TOOL_NAME',
GET_BEAN_NAME = 'GET_BEAN_NAME',
GET_MILL_NAME = 'GET_MILL_NAME',
GET_PREPARATION_NAME = 'GET_PREPARATION_NAME',
GET_WATER_NAME = 'GET_WATER_NAME',
}
10 changes: 10 additions & 0 deletions src/pipes/brew/brewFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,18 @@ export class BrewFunction implements PipeTransform {
return value.getFormattedBrewTime();
case BREW_FUNCTION_PIPE_ENUM.FORMATTED_COFFEE_BREW_TIME:
return value.getFormattedCoffeeBrewTime();
case BREW_FUNCTION_PIPE_ENUM.FORMATTED_TOTAL_COFFEE_BREW_TIME:
return value.getFormattedTotalCoffeeBrewTime();
case BREW_FUNCTION_PIPE_ENUM.GET_PREPARATION_TOOL_NAME:
return value.getPreparationToolName(arg[1]);
case BREW_FUNCTION_PIPE_ENUM.GET_BEAN_NAME:
return value.getBean().name;
case BREW_FUNCTION_PIPE_ENUM.GET_MILL_NAME:
return value.getMill().name;
case BREW_FUNCTION_PIPE_ENUM.GET_PREPARATION_NAME:
return value.getPreparation().name;
case BREW_FUNCTION_PIPE_ENUM.GET_WATER_NAME:
return value.getWater().name;
}
} catch (ex) {}
}
Expand Down
2 changes: 0 additions & 2 deletions src/services/uiBrewStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export class UIBrewStorage extends StorageClass {
public async add(_entry: Brew): Promise<any> {
_entry.fixDataTypes();
const addEntry = this.uiHelper.cloneData(_entry);
addEntry.deleteCachingObjects();
return await super.add(addEntry);
}

Expand All @@ -81,7 +80,6 @@ export class UIBrewStorage extends StorageClass {
_obj.fixDataTypes();

const updatingObj = this.uiHelper.cloneData(_obj);
updatingObj.deleteCachingObjects();
const updateval: boolean = await super.update(updatingObj);
resolve(updateval);
});
Expand Down

0 comments on commit d0cf93b

Please sign in to comment.