mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
fix: accounts types caching.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import TenantRepository from 'repositories/TenantRepository';
|
||||
import { IAccount } from 'interfaces';
|
||||
|
||||
export default class AccountRepository extends TenantRepository {
|
||||
models: any;
|
||||
@@ -33,9 +34,9 @@ export default class AccountRepository extends TenantRepository {
|
||||
|
||||
/**
|
||||
* Retrieve all accounts on the storage.
|
||||
* @return {}
|
||||
* @return {IAccount[]}
|
||||
*/
|
||||
allAccounts() {
|
||||
allAccounts(): IAccount[] {
|
||||
const { Account } = this.models;
|
||||
return this.cache.get('accounts', async () => {
|
||||
return Account.query();
|
||||
@@ -45,8 +46,9 @@ export default class AccountRepository extends TenantRepository {
|
||||
/**
|
||||
* Retrieve account of the given account slug.
|
||||
* @param {string} slug
|
||||
* @return {IAccount}
|
||||
*/
|
||||
getBySlug(slug: string) {
|
||||
getBySlug(slug: string): IAccount {
|
||||
const { Account } = this.models;
|
||||
return this.cache.get(`accounts.slug.${slug}`, () => {
|
||||
return Account.query().findOne('slug', slug);
|
||||
@@ -56,8 +58,9 @@ export default class AccountRepository extends TenantRepository {
|
||||
/**
|
||||
* Retrieve the account by the given id.
|
||||
* @param {number} id - Account id.
|
||||
* @return {IAccount}
|
||||
*/
|
||||
getById(id: number) {
|
||||
getById(id: number): IAccount {
|
||||
const { Account } = this.models;
|
||||
return this.cache.get(`accounts.id.${id}`, () => {
|
||||
return Account.query().findById(id);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import TenantRepository from 'repositories/TenantRepository';
|
||||
import { IAccountType } from 'interfaces';
|
||||
|
||||
export default class AccountTypeRepository extends TenantRepository {
|
||||
cache: any;
|
||||
@@ -17,29 +18,62 @@ export default class AccountTypeRepository extends TenantRepository {
|
||||
this.cache = this.tenancy.cache(tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all accounts types.
|
||||
* @return {IAccountType[]}
|
||||
*/
|
||||
all() {
|
||||
const { AccountType } = this.models;
|
||||
return this.cache.get('accountType.all', () => {
|
||||
return AccountType.query();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve account type meta.
|
||||
* @param {number} accountTypeId
|
||||
* @return {IAccountType}
|
||||
*/
|
||||
getTypeMeta(accountTypeId: number) {
|
||||
getTypeMeta(accountTypeId: number): IAccountType {
|
||||
const { AccountType } = this.models;
|
||||
return this.cache.get(`accountType.${accountTypeId}`, () => {
|
||||
return this.cache.get(`accountType.id.${accountTypeId}`, () => {
|
||||
return AccountType.query().findById(accountTypeId);
|
||||
});
|
||||
}
|
||||
|
||||
getByKeys(keys: string[]) {
|
||||
/**
|
||||
* Retrieve accounts types of the given keys.
|
||||
* @param {string[]} keys
|
||||
* @return {IAccountType[]}
|
||||
*/
|
||||
getByKeys(keys: string[]): IAccountType[] {
|
||||
const { AccountType } = this.models;
|
||||
return AccountType.query().whereIn('key', keys);
|
||||
return this.cache.get(`accountType.keys.${keys.join(',')}`, () => {
|
||||
return AccountType.query().whereIn('key', keys);
|
||||
});
|
||||
}
|
||||
|
||||
getByKey(key: string) {
|
||||
/**
|
||||
* Retrieve account tpy eof the given key.
|
||||
* @param {string} key
|
||||
* @return {IAccountType}
|
||||
*/
|
||||
getByKey(key: string): IAccountType {
|
||||
const { AccountType } = this.models;
|
||||
return AccountType.query().findOne('key', key);
|
||||
return this.cache.get(`accountType.key.${key}`, () => {
|
||||
return AccountType.query().findOne('key', key);
|
||||
});
|
||||
}
|
||||
|
||||
getByRootType(rootType: string) {
|
||||
/**
|
||||
* Retrieve accounts types of the given root type.
|
||||
* @param {string} rootType
|
||||
* @return {IAccountType[]}
|
||||
*/
|
||||
getByRootType(rootType: string): IAccountType[] {
|
||||
const { AccountType } = this.models;
|
||||
return AccountType.query().where('root_type', rootType);
|
||||
return this.cache.get(`accountType.rootType.${rootType}`, () => {
|
||||
return AccountType.query().where('root_type', rootType);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user