I have used the xmlsitemap module to generate the organic search xmlsitemap and i extended the module using hook_xmlsitemap_element_alter for adding the image and video tags. I am having the node id info and i need to load the node for getting the attached image and video references. To get the details of the image and videos, i need to load the reference ids again. My site is having more than 10k nodes and xmlsitemap is throwing the time out error. I found the problem is due to the heavy node load operations.
But my question if we are running this operation in a batch, it should not fail. I have seen that the following lines of code in a while loop in xmlsitemap.generate.inc
Code at line number 232.
drupal_alter('xmlsitemap_element', $element, $link, $sitemap);
$writer->writeSitemapElement('url', $element);
Should above lines of code go in a batch?
My code
function mymodue_xmlsitemap_xmlsitemap_element_alter(array &$element, array $link, $sitemap) {
if ($link['subtype'] == 'article') {
mymodule_xmlsitemap_get_tags($element, $link);
}
}
*/
function mymodule_xmlsitemap_get_tags(&$tag_info, $result) {
$node = node_load($result['id']);
$image_ref = $node->field_image['und'][0]['target_id'];
$video_ref = node->field_video['und'][0]['target_id'];
$image_node = node_load($image_ref);
/*
code goes here
*/
}
Please give me suggestions.