TYPO3 Extbase-在一个大表中分页(100000条记录)
我有一个相当大的表,大约有100000条记录。如果我没有在存储库中设置限制 存储库:TYPO3 Extbase-在一个大表中分页(100000条记录),typo3,extbase,typo3-7.6.x,Typo3,Extbase,Typo3 7.6.x,我有一个相当大的表,大约有100000条记录。如果我没有在存储库中设置限制 存储库: public function paginateRequest() { $query = $this->createQuery(); $result = $query->setLimit(1000)->execute(); //$result = $query->execute(); return $result; } /** * action list * * @retur
public function paginateRequest() {
$query = $this->createQuery();
$result = $query->setLimit(1000)->execute();
//$result = $query->execute();
return $result;
}
/**
* action list
*
* @return void
*/
public function listAction() {
$this->view->assign('records', $this->leiRepository->paginateRequest());
//$this->view->assign('records', $this->leiRepository->findAll());
}
。。。尽管我使用的是f:widget.paginate,但查询和页面仍会中断。根据文档,我希望我能通过记录只呈现itemsPerPage和“parginate”
List.hmtl
<f:if condition="{records}">
<f:widget.paginate objects="{records}" as="paginatedRecords" configuration="{itemsPerPage: 100, insertAbove: 0, insertBelow: 1, maximumNumberOfLinks: 10}">
<f:for each="{paginatedRecords}" as="record">
<tr>
<td><f:link.action action="show" pageUid="43" arguments="{record:record}"> {record.name}</f:link.action></td>
<td><f:link.action action="show" pageUid="43" arguments="{record:record}"> {record.lei}</f:link.action></td>
</tr>
</f:for>
</f:widget.paginate>
要分页的对象有多大/复杂?如果它们具有列表视图中不需要的子对象,请将@lazy注释添加到模型内的这些关系中 由于记录数量如此之多,您应该在列表视图中尽可能简单地保存它们。您可以尝试使用
$this->leiRepository->findAll()->toArray()
将结果作为数组提供给列表视图,或者通过添加true以执行(true)只返回存储库中的原始结果
您还可以自己在控制器的foreach中创建列表项数组,并且只在列表中添加您真正需要的属性 如果您的问题是性能,只需使用默认的findAll()-方法 \TYPO3\CMS\Extbase\Persistence\Repository中的内置defaultQuerySettings基于分页小部件设置它们的偏移量和限制(如果没有其他设置)
如果性能问题仍然存在,您可能不得不考虑为数据库请求编写自定义查询,它只请求视图实际显示的数据。文档中描述了该过程:
我在TYPO3 9.5中使用。存储库中的下一个功能:public function paginated($page = 1, $size = 9){
$query = $this->createQuery();
$begin = ($page-1) * $size;
$query->setOffset($begin);
$query->setLimit($size);
return $query->execute();
}
在控制器中,我使用参数作为参数,在Rest操作中发送要加载的页面
public function listRestAction()
{
$arguments = $this->request->getArguments();
$totalElements = $this->repository->total();
$pages = ceil($totalElements/9);
$next_page = '';
$prev_page = '';
#GET Page to load
if($arguments['page'] AND $arguments['page'] != ''){
$page_to_load = $arguments['page'];
} else {
$page_to_load = 1;
}
#Configuration of pagination
if($page_to_load == $pages){
$prev = $page_to_load - 1;
$prev_page = "http://example.com/rest/news/page/$prev";
} elseif($page_to_load == 1){
$next = $page_to_load + 1;
$next_page = "http://example.com/rest/news/page/$next";
} else {
$prev = $page_to_load - 1;
$prev_page = "http://example.com/rest/news/page/$prev";
$next = $page_to_load + 1;
$next_page = "http://example.com/rest/news/page/$next";
}
$jsonPreparedElements = array();
$jsonPreparedElements['info']['count'] = $totalElements;
$jsonPreparedElements['info']['pages'] = $pages;
$jsonPreparedElements['info']['next'] = $next_page;
$jsonPreparedElements['info']['prev'] = $prev_page;
$result = $this->repository->paginated($page_to_load);
$collection_parsed_results = array();
foreach ($result as $news) {
array_push($collection_parsed_results, $news->parsedArray());
}
$jsonPreparedElements['results'] = $collection_parsed_results;
$this->view->assign('value', $jsonPreparedElements);
}
其结果是一个JSON,如下所示:
{
"info": {
"count": 25,
"pages": 3,
"next": "",
"prev": "http://example.com/rest/news/page/2"
},
"results": [
{ ....}
] }
谢谢你,保罗。我尝试了@lazy load,->toArray()并执行(true)。。。但它还是坏了。当您询问“对象应该有多大/多复杂”时。。。您是说每个分页选项卡要在列表视图中显示多少条记录?我希望至少100。。。还有子对象?
{
"info": {
"count": 25,
"pages": 3,
"next": "",
"prev": "http://example.com/rest/news/page/2"
},
"results": [
{ ....}
] }