我的应用程序db刚刚超过100gb,很快就会崩溃。
我可以保存它,如果我可以用一个静态页面替换CListView的第一个结果页面。
对于服务器来说打印静态页面更容易。我可以很容易地重新生成静态页面,每天根据需要。
没有代码,因为我不知道如何修改ClistView来达到我的目标,如果可能的话;
在使用内存分配时找到答案;
对于那些知道如何处理内存的人来说,有一个术语SENTINEL
当向队列中添加新数据时,您必须为数据找到正确的位置,然后插入它
通过使用哨兵,您将始终在队列 中至少有2个元素。这是我需要达到的
我需要在clistview的第一个元素之前放一个哨兵
我需要操作clistview;我只想设置clistview的第一页,用我的静态页面
也许分页将设置为40个元素,而我的静态页面将每页1000个
但是当用户打开第2页、第3页或第4页时……Clistview应该列出接下来的40
对于第2页,clistview实际上会列出第一个真实的结果;
您可以根据CListView
的页面索引使用不同的页面缓存。当然,这不如返回静态页面快,但可以显著提高性能。
为了取代链接到CListView
的第一页,你可以覆盖createPageUrl方法的CLinkPager:
<?php
class StaticLinkPager extends CLinkPager
{
public $firstPageUrl;
protected function createPageUrl($page)
{
if ($page == 1)
return $this->firstPageUrl;
return parent::createPageUrl($page);
}
}
并与CListView
一起使用,将其pager属性设置为:
array(
'class' => 'StaticLinkPager',
'firstPageUrl' => '/list-view-first-static-page.html'
)
从你的评论中我猜你可能想要这样的东西:
<?php if($dataProvider->pagination->currentPage==0): ?>
<?php /*
Render your static content + a custom CLinkPager here.
Feed $dataProvider->pagination as 'pages' into the link pager.
*/ ?>
<?php else: ?>
<?php /* Render your listview here */ ?>
<?php endif; ?>
正如我在上面的评论中所说的,你仍然会看到一个查询来获取项目计数。只要为"静态"内容渲染分页,就无法避免这种情况。