Skip to content

Firefly III: a personal finances manager

Add limit #3150

James Cole62fd701808a4
diff --git a/app/Api/V1/Controllers/Autocomplete/AccountController.php b/app/Api/V1/Controllers/Autocomplete/AccountController.php
index 2e985ba476..7ca320ff92 100644
--- a/app/Api/V1/Controllers/Autocomplete/AccountController.php
+++ b/app/Api/V1/Controllers/Autocomplete/AccountController.php
@@ -63,7 +63,6 @@ class AccountController extends Controller
}
/**
- * TODO add limit
* @param AutocompleteRequest $request
*
* @return JsonResponse
@@ -78,7 +77,7 @@ class AccountController extends Controller
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$return = [];
- $result = $repository->searchAccount((string) $query, $types);
+ $result = $repository->searchAccount((string) $query, $types, $data['limit']);
$defaultCurrency = app('amount')->getDefaultCurrency();
/** @var Account $account */
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php
index 32d02df306..24e499ae20 100644
--- a/app/Repositories/Account/AccountRepository.php
+++ b/app/Repositories/Account/AccountRepository.php
@@ -559,10 +559,11 @@ class AccountRepository implements AccountRepositoryInterface
/**
* @param string $query
* @param array $types
+ * @param int $limit
*
* @return Collection
*/
- public function searchAccount(string $query, array $types): Collection
+ public function searchAccount(string $query, array $types, int $limit): Collection
{
$dbQuery = $this->user->accounts()
->where('active', 1)
@@ -582,7 +583,7 @@ class AccountRepository implements AccountRepositoryInterface
$dbQuery->whereIn('account_types.type', $types);
}
- return $dbQuery->get(['accounts.*']);
+ return $dbQuery->take($limit)->get(['accounts.*']);
}
/**
diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php
index 176df182fc..f5cf03cfef 100644
--- a/app/Repositories/Account/AccountRepositoryInterface.php
+++ b/app/Repositories/Account/AccountRepositoryInterface.php
@@ -276,10 +276,11 @@ interface AccountRepositoryInterface
/**
* @param string $query
* @param array $types
+ * @param int $limit
*
* @return Collection
*/
- public function searchAccount(string $query, array $types): Collection;
+ public function searchAccount(string $query, array $types, int $limit): Collection;
/**
* @param User $user
diff --git a/app/Support/Search/Search.php b/app/Support/Search/Search.php
index fa09873cd9..f907f53174 100644
--- a/app/Support/Search/Search.php
+++ b/app/Support/Search/Search.php
@@ -214,7 +214,7 @@ class Search implements SearchInterface
case 'source':
// source can only be asset, liability or revenue account:
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::REVENUE];
- $accounts = $this->accountRepository->searchAccount($modifier['value'], $searchTypes);
+ $accounts = $this->accountRepository->searchAccount($modifier['value'], $searchTypes, 25);
if ($accounts->count() > 0) {
$totalAccounts = $accounts->merge($totalAccounts);
}
@@ -223,7 +223,7 @@ class Search implements SearchInterface
case 'destination':
// source can only be asset, liability or expense account:
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::EXPENSE];
- $accounts = $this->accountRepository->searchAccount($modifier['value'], $searchTypes);
+ $accounts = $this->accountRepository->searchAccount($modifier['value'], $searchTypes, 25);
if ($accounts->count() > 0) {
$totalAccounts = $accounts->merge($totalAccounts);
}