I'm working on a site with usasearch and usasearch_api modules enabled. Everything appears to be functioning correctly - new nodes that are created as published are indexed, nodes that are created as unpublished and then later published are indexed on cron, updated nodes are updated in the index correctly.
The issue is that whenever a published node is updated, and it is not changing from unpublished to published in the update, usasearch_api errors appear in watchdog. I've narrowed down the cause to code in usasearch_api.module:
18 /**
19 * Implements hook_node_update().
20 */
21 function usasearch_api_node_update($node) {
22 // Delete from index if node has been unpublished
23 if ($node->status == 0) {
24 usasearch_api_node_delete($node);
25 return;
26 } else {
27 // attempt insert in case the node is changing from unpublished to published
28 usasearch_api_node_insert($node);
29 }
30 $document = usasearch_api_convert_node_to_document($node);
31 if ($document) {
32 usasearch_api_request('put', 'api/v1/documents/' . $document->getDocumentId(), array('json' => $document->json()));
33 }
34 }
Specifically, line 28 where it attempts to force an insert in the index without checking if the node status actually changed (and therefore needs to be inserted). So nodes that are already indexed are triggering an error from the API, which is added to watchdog. Line 32 then performs an update request on the index, which works. So functionality isn't affected, but there are unnecessary errors appearing in the logs.
Comment | File | Size | Author |
---|---|---|---|
#2 | 2745101-unnecessary-call-to-insert.patch | 1.09 KB | lisagodare |
Comments
Comment #2
lisagodareI've attached a patch that looks at $node->original->status and $node->status to determine if an insert is required. It'll insert or update depending on the original status.
Comment #3
lisagodareComment #4
schiavone CreditAttribution: schiavone at Snake Hill Web Agency commentedLooks like this will work. I'll check it out. We're also going to starting logging indexing operations so we'll know whether a node has been pushed to the index.
Comment #6
schiavone CreditAttribution: schiavone at Snake Hill Web Agency commentedChanges from the patch have been incorporated along with index logging so that unnecessary REST calls are not made reducing errors