PostIterator doesn't include links
adampash opened this issue · comments
Certainly possible that this is intentional, but we'll need it for at least #2130 and #2139. Anyway, in class.PostIterator.php adding:
$post = new Post($row);
// added two lines below
$link_dao = new LinkMySQLDAO();
$post->links = $link_dao->getLinksForPost($post->post_id, $post->network);
$this->row = $post;
$this->valid = true;
Does the trick... but maybe not best practice. Test assertion to add to TestOfPostIterator.php:
foreach($post_it as $key => $value) {
$this->assertEqual($value->post_text, $posts[$cnt]->post_text);
// added single assertion below
$this->assertEqual(sizeof($value->links), sizeof($posts[$cnt]->links));
$this->assertIsA($value, 'Post');
$cnt++;
}
If this or something like it is cool, lemme know and I can issue a PR.
I always assumed this was on purpose, since we use the iterator in
situations where we're concerned about result size.
It'd be ideal to make it optional. Or maybe Post could have a getLinks()
method that lazy loads links if they aren't loaded.
On Tue, Nov 18, 2014 at 4:58 PM Adam Pash notifications@github.com wrote:
Certainly possible that this is intentional, but we'll need it for at
least #2130 #2130 and #2139
#2139. Anyway, in
class.PostIterator.php adding:$post = new Post($row); // added below $link_dao = new LinkMySQLDAO(); $post->links = $link_dao->getLinksForPost($post->post_id, $post->network); $this->row = $post; $this->valid = true;
Does the trick... but maybe not best practice. Test assertion to add to
TestOfPostIterator.php:foreach($post_it as $key => $value) { $this->assertEqual($value->post_text, $posts[$cnt]->post_text); // added assertion below $this->assertEqual(sizeof($value->links), sizeof($posts[$cnt]->links)); $this->assertIsA($value, 'Post'); $cnt++; }
If this or something like it is cool, lemme know and I can issue a PR.
—
Reply to this email directly or view it on GitHub
#2159.
Sure, that's fine, too.
My understanding was that size was an issue in that we didn't want thousands of Post objects, in which case including the links with a single post when we do iterate on it doesn't seem like a huge size concern. Admittedly, though, I probably know the least behind the thinking that went into the iterator.
Anyway, as long as we've got a simple way to grab the links, I'm happy!
This is currently in staging and will get merged into thinkup.com with the dependent EOY insights a1c3d4b