elrond
(Dominik Frukacz)
April 12, 2013, 6:57am
1
hi
I’ve got method:
protected function findUsersBatch($companyId,$page=1)
{
$criteria=new CDbCriteria();
$criteria->compare('company_id',$companyId);
$criteria->compare('active',0);
$criteria->addCondition('import_time IS NOT NULL');
$criteria->addCondition('invite_time IS NULL');
$criteria->limit=self::BATCH_SIZE;
$criteria->offset=($page-1)*self::BATCH_SIZE;
return User::model()->findAll($criteria);
}
and loop which iterates over it
$page=1;
while($data=$this->findUsersBatch($companyId,$page))
{
foreach($data as $item)
{
...do stuff
}
$page++;
}
batch size is 100
for given comapny I’v got ex. 1890 records
this code does 1000 recordes and stops
am’I missig smth here?
lalzada
(Lalzadamohmand)
April 12, 2013, 7:24am
2
$criteria->limit=self::BATCH_SIZE;
if your cirtieria->limit is 100 so it wil fetch only first 100 records
your $page is 1 so at every call to
$this->findUsersBatch($companyId,$page)
critieria offset is 0
elrond
(Dominik Frukacz)
April 12, 2013, 7:44am
3
$criteria->limit=self::BATCH_SIZE;
if your cirtieria->limit is 100 so it wil fetch only first 100 records
your $page is 1 so at every call to
$this->findUsersBatch($companyId,$page)
critieria offset is 0
no - $page is incremented
while($data=$this->findUsersBatch($companyId,$page))
{
foreach($data as $item)
{
...do stuff
}
$page++; <!----------- increment $page by one
}
it’s working witch first 10 “pages” (so it is iterating over fisrst 1000 records)
after it stopas (as findUsersBatch do not return recorsds)
lalzada
(Lalzadamohmand)
April 12, 2013, 8:19am
4
i try this…and it returns even >1200 records…
public function findUsersBatch($page=1){
$criteria=new CDbCriteria();
$criteria->limit=100;
$criteria->offset=($page-1)*100;
return Contact::model()->findAll($criteria);
}
$page=1;
while($data=$this->findUsersBatch($page))
{
foreach($data as $item)
{
echo $item->id."<br>";
}
$page++;
}
which view you have used…CGridVIew or CListView ?
elrond
(Dominik Frukacz)
April 12, 2013, 8:28am
5
i try this…and it returns even >1200 records…
public function findUsersBatch($page=1){
$criteria=new CDbCriteria();
$criteria->limit=100;
$criteria->offset=($page-1)*100;
return Contact::model()->findAll($criteria);
}
$page=1;
while($data=$this->findUsersBatch($page))
{
foreach($data as $item)
{
echo $item->id."<br>";
}
$page++;
}
which view you have used…CGridVIew or CListView ?
non of them, i use it in command to send emails (this is done in foreach on batch)
I’have also tried other version: i’ve made method countUsersToInvite() and chaged while loop
while($this->countUsersToInvite($companyId)) {
$data=$this->findUsersBatch($page);
foreach .....
$page++;
}
and debug it, with each iteration count showed less records but after 1000 it stoped and $page stated to incerement to infinite