The function http://api.drupal.org/api/function/search_touch_node/7 is used to let various operations say "This node has changed and needs to be reindexed".

It works by setting the .reindex field in {search_dataset} to the current request time. Then in node_update_index(), a query is run that orders nodes by their .reindex field, and picks out the lowest-numbered N nodes for reindexing.

The problem is that if a node has been previously marked for reindexing when search_touch_node() is called, search_touch_node() will set its reindex field to a higher number (because it's a later request), thereby lowering its priority for reindexing.

So instead, search_touch_node() should check to see if the reindex bit is already set to something non-zero, and not change it if it is. It should also only try to do the update if the node already exists in the table, probably? But that may be a moot point if #312395: Queries on search admin and node indexing are slow for many-node sites is fixed by making sure every node gets added to the table when first created anyway.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

Title: search_touch_node() should not update if already touched » search_touch_node()/search_mark_for_reindex() should not update if already touched
Version: 7.x-dev » 8.x-dev
Issue summary: View changes
Issue tags: +Needs backport to D7

This applies to D8 too. The D8 function is more generic and is called search_mark_for_reindex(), but it does the same thing.

jhodgdon’s picture

Status: Active » Needs review
FileSize
993 bytes

Here's a patch. I tested it manually and it works fine.

We have tests for reindexing, so hopefully they will still work. I guess we could add a new test for this behavior, but I'm not sure how necessary that is?

jhodgdon’s picture

2: 735154.patch queued for re-testing.

jhodgdon’s picture

2: 735154.patch queued for re-testing.

jhodgdon’s picture

2: 735154.patch queued for re-testing.

pwolanin’s picture

FileSize
425 bytes

It would seem a lot easier to add a condition to the update query?

I'm not clear why you need the GROUP BY if the reindex query always sets items with the same sid to the same timestamp?

Also, it would be helpful to have a test of the logic here?

jhodgdon’s picture

Assigned: Unassigned » jhodgdon
Status: Needs review » Needs work

Doh! I like the patch in #6. A test would indeed be a good idea. I'll get on that.

jhodgdon’s picture

Status: Needs work » Needs review
FileSize
1.84 KB
1.43 KB

OK! Here's the (one-line, ultra-simple, really great) patch from pwolanin #6, with a test added, plus a test-only patch that fails.

Assuming that the test bot agrees with my local test results (test fails without patch, passes with), I would be +1 on RTBC. Someone other than me will need to give the test a quick review.

And if you're wondering why the test is in the "Mutlilingual" test, that is where we are currently testing things related to reindexing and throttling, for what it's worth. I just added a few more lines to the existing test there. Probably we should rename that test, but I think that's a separate issue.

The last submitted patch, 8: 735154-with-tests-8.patch, failed testing.

jhodgdon’s picture

8: 735154-with-tests-8.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 8: 735154-test-only-FAIL-8.patch, failed testing.

jhodgdon’s picture

Status: Needs work » Needs review

OK, the tests passed/failed as expected. I endorse the code fix from pwolanin for RTBC. Anyone want to review the test I wrote so we can get this easy change in?

pwolanin’s picture

We should probably add a code comment explaining why the condition is there?

jhodgdon’s picture

FileSize
1.98 KB

Good idea. Here's one more patch, this time with a 2-line comment. Small patch, didn't bother with interdiff, hope that is OK. The only difference is the new comment in search_mark_for_reindex().

Nick_vh’s picture

I'm not entirely sure about the reindex column but it's looking good and it's a simple patch.

Nick_vh’s picture

Status: Needs review » Reviewed & tested by the community
jhodgdon’s picture

Assigned: jhodgdon » Unassigned
alexpott’s picture

Committed 9f92f4e and pushed to 8.x. Thanks!

  • Commit 9f92f4e on 8.x by alexpott:
    Issue #735154 by jhodgdon, pwolanin: Fixed search_touch_node()/...
jhodgdon’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

  • alexpott committed 9f92f4e on 8.3.x
    Issue #735154 by jhodgdon, pwolanin: Fixed search_touch_node()/...

  • alexpott committed 9f92f4e on 8.3.x
    Issue #735154 by jhodgdon, pwolanin: Fixed search_touch_node()/...

  • alexpott committed 9f92f4e on 8.4.x
    Issue #735154 by jhodgdon, pwolanin: Fixed search_touch_node()/...

  • alexpott committed 9f92f4e on 8.4.x
    Issue #735154 by jhodgdon, pwolanin: Fixed search_touch_node()/...