mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 22:28:51 +01:00
Fix caching of number of searched records
This commit is contained in:
parent
f2973adfff
commit
e20d737d63
@ -44,11 +44,12 @@ abstract class SearchProvider
|
||||
abstract public function getName(): string;
|
||||
|
||||
/**
|
||||
* Search results
|
||||
* Run search process, result may be cached
|
||||
*
|
||||
* @return SearchRecordInterface[]
|
||||
* @return array 'totalCount' - Number of total searched records,
|
||||
* 'results' - Array of searched records SearchRecordInterface[]
|
||||
*/
|
||||
abstract public function searchResults(): array;
|
||||
abstract public function runSearch(): array;
|
||||
|
||||
/**
|
||||
* Run search process and cache results
|
||||
@ -61,10 +62,13 @@ abstract class SearchProvider
|
||||
return;
|
||||
}
|
||||
|
||||
$this->results = Yii::$app->cache->getOrSet(
|
||||
$data = Yii::$app->cache->getOrSet(
|
||||
static::class . Yii::$app->user->id . ':search:' . $this->keyword,
|
||||
[$this, 'searchResults'],
|
||||
[$this, 'runSearch'],
|
||||
$this->cacheTimeout);
|
||||
|
||||
$this->totalCount = $data['totalCount'] ?? 0;
|
||||
$this->results = $data['results'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,7 +42,7 @@ class ContentSearchProvider extends SearchProvider
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function searchResults(): array
|
||||
public function runSearch(): array
|
||||
{
|
||||
/* @var Module $module */
|
||||
$module = Yii::$app->getModule('content');
|
||||
@ -52,13 +52,14 @@ class ContentSearchProvider extends SearchProvider
|
||||
'pageSize' => $this->pageSize
|
||||
]));
|
||||
|
||||
$this->totalCount = $resultSet->pagination->totalCount;
|
||||
|
||||
$results = [];
|
||||
foreach ($resultSet->results as $content) {
|
||||
$results[] = new SearchRecord($content);
|
||||
}
|
||||
|
||||
return $results;
|
||||
return [
|
||||
'totalCount' => $resultSet->pagination->totalCount,
|
||||
'results' => $results
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -43,20 +43,21 @@ class SpaceSearchProvider extends SearchProvider
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function searchResults(): array
|
||||
public function runSearch(): array
|
||||
{
|
||||
$spaceDirectoryQuery = new SpaceDirectoryQuery([
|
||||
'defaultFilters' => ['keyword' => $this->keyword],
|
||||
'pageSize' => $this->pageSize
|
||||
]);
|
||||
|
||||
$this->totalCount = $spaceDirectoryQuery->pagination->totalCount;
|
||||
|
||||
$results = [];
|
||||
foreach ($spaceDirectoryQuery->all() as $space) {
|
||||
$results[] = new SearchRecord($space);
|
||||
}
|
||||
|
||||
return $results;
|
||||
return [
|
||||
'totalCount' => $spaceDirectoryQuery->pagination->totalCount,
|
||||
'results' => $results
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -43,20 +43,21 @@ class UserSearchProvider extends SearchProvider
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function searchResults(): array
|
||||
public function runSearch(): array
|
||||
{
|
||||
$peopleQuery = new PeopleQuery([
|
||||
'defaultFilters' => ['keyword' => $this->keyword],
|
||||
'pageSize' => $this->pageSize
|
||||
]);
|
||||
|
||||
$this->totalCount = $peopleQuery->pagination->totalCount;
|
||||
|
||||
$results = [];
|
||||
foreach ($peopleQuery->all() as $user) {
|
||||
$results[] = new SearchRecord($user);
|
||||
}
|
||||
|
||||
return $results;
|
||||
return [
|
||||
'totalCount' => $peopleQuery->pagination->totalCount,
|
||||
'results' => $results
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user