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

Batch load message entities in view results #229

Open
wants to merge 1 commit into
base: 7.x-1.x
Choose a base branch
from

Conversation

nikanderson
Copy link

Adds a pre_render method to message_handler_field_message_render in order to batch-load Message entities rather than loading them one by one in render()

@@ -12,6 +12,9 @@
*/
class message_handler_field_message_render extends views_handler_field {

// Message entities
var $messages = array();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid this $messages - as we end up caching this inside message_load and here. Instead - you can do something like:

function pre_render() {

...
+    if (empty($mids)) {
        // No Message IDs.
        return;
     }
     
    // Load the Messages in a single call, so they will be statically cached in the ::render function.
     message_load_multiple($mids);
}

Then, the render function will stay as-is, the message_load will however fetch the $message from the static cache.

$field_alias = $this->field_alias;

foreach ($values as $value) {
if (!empty($value->{$field_alias})) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would this be empty?

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

Successfully merging this pull request may close these issues.

3 participants