Skip to content

Commit

Permalink
#837 - Set caching amount on saving
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Nov 9, 2024
1 parent b77a071 commit 424e059
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/classes/brew/brew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ 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 {
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;
Expand Down
6 changes: 5 additions & 1 deletion src/services/uiBrewStorage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** Core */
import { Injectable } from '@angular/core';
/** Class */
import { Brew } from '../classes/brew/brew';
import { Brew, BrewInstanceHelper } from '../classes/brew/brew';
/** Services */
import { StorageClass } from '../classes/storageClass';
import { UIHelper } from './uiHelper';
Expand Down Expand Up @@ -71,12 +71,16 @@ export class UIBrewStorage extends StorageClass {
}
public async add(_entry: Brew): Promise<any> {
_entry.fixDataTypes();
//We cache objects, it should be enough to zero it back when adding/editing something
BrewInstanceHelper.setEntryAmountBackToZero();
return await super.add(_entry);
}

public async update(_obj: Brew): Promise<boolean> {
const promise: Promise<any> = new Promise(async (resolve, reject) => {
_obj.fixDataTypes();
//We cache objects, it should be enough to zero it back when adding/editing something
BrewInstanceHelper.setEntryAmountBackToZero();
const updateval: boolean = await super.update(_obj);
resolve(updateval);
});
Expand Down

0 comments on commit 424e059

Please sign in to comment.