Skip to content

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()

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