Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub-optimal loops #1

Open
litzinger opened this issue Oct 22, 2015 · 1 comment
Open

Sub-optimal loops #1

litzinger opened this issue Oct 22, 2015 · 1 comment

Comments

@litzinger
Copy link

You're doing a lot of extra queries in the loop you have setup. It looks like the filter method may support an 'IN' operator as the 3rd argument.

$members = ee('Model')->get('Member')->all();
$memberIds = [];

// Do something here, a loop maybe, to get all the member ids.

$data = "";
$count = 0;
$entries = ee('Model')->get('ChannelEntry')
    ->filter('channel_id', $channel)
    ->filter('author_id', $memberIds, 'IN')
    ->all();

// Would count($entries) work here instead?
foreach ($entries as $entry) {
    $count++;
}
if ($count != 0) {
    $data["mem_id"] = $member->member_id;
    $data["mem_name"] = $member->screen_name;
    $data["counted"] = $count;
    $vars[] = $data;
}

@litzinger
Copy link
Author

You're also defining $data as a string, then later using it as an array.

$data = [];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant