Skip to content

Commit

Permalink
Bugfix: Search out of memory error
Browse files Browse the repository at this point in the history
Should have been using a post iterator
Closes ThinkUpLLC#665, closes ThinkUpLLC#666
  • Loading branch information
mwilkie authored and ginatrapani committed Mar 8, 2011
1 parent 8363336 commit 4d2e8a2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/TestOfPostMySQLDAO.php
Expand Up @@ -534,6 +534,7 @@ public function testGetAllPostIterators() {
$dao = new PostMySQLDAO();
$posts_it = $dao->getAllPostsIterator(18, 'twitter', 10);
$cnt = 0;
$this->assertIsA($posts_it,'PostIterator');
foreach($posts_it as $key => $value) {
$cnt++;
}
Expand Down
4 changes: 4 additions & 0 deletions webapp/_lib/controller/class.GridController.php
Expand Up @@ -104,6 +104,10 @@ public function authControl() {
}
echo '{"status":"success","posts": [' . "\n";
$cnt = 0;
// lets make sure we have a post iterator, and not just a list of posts
if( get_class($posts_it) != 'PostIterator' ) {
throw Exception("Grid Search should use a PostIterator to conserve memory");
}
foreach($posts_it as $key => $value) {
$cnt++;
$data = array('id' => $cnt, 'text' => $value->post_text,
Expand Down
5 changes: 4 additions & 1 deletion webapp/_lib/model/class.PostMySQLDAO.php
Expand Up @@ -585,7 +585,8 @@ public function getAllPosts($author_id, $network, $count, $page=1, $include_repl
}

public function getAllPostsIterator($author_id, $network, $count, $include_replies=true) {
return $this->getAllPostsByUserID($author_id, $network, $count, "pub_date", "DESC", $include_replies, $iterator = true);
return $this->getAllPostsByUserID($author_id, $network, $count, "pub_date", "DESC", $include_replies, $page = 1,
$iterator = true);
}

public function getAllQuestionPosts($author_id, $network, $count, $page=1) {
Expand Down Expand Up @@ -655,7 +656,9 @@ private function getAllPostsByUserID($author_id, $network, $count, $order_by="pu
':limit'=>$count,
':start_on_record'=>(int)$start_on_record
);

$ps = $this->execute($q, $vars);

if($iterator) {
return (new PostIterator($ps));
}
Expand Down

0 comments on commit 4d2e8a2

Please sign in to comment.