function realname_update_index() {
    
    ...

    $result = db_query_range("SELECT uid, name FROM {users} WHERE status=1 AND uid>=%d", $start, 0, $limit);
    while ($account = db_fetch_object($result)) {
        ...
      variable_set('realname_last_index', $account->uid);
    }
  }
} 

realname_update_index() function re-index items and remembers last reindexed user. Unfortunately, "select ..." query does not use "ORDER BY" clause so order of re-indexing is not defined. It means if there are 10 users to be reindexed and their UIDs are 1..10 then MySQL can return these in any order, for example 2,3,4,5,6,7,8,9,10,1. As result, 'realname_last_index' variable will remember 1 as last re-indexed user and it will cause full re-indexing of the same data again.

Proposed change - order users by UID before re-indexing, i.e.

function realname_update_index() {
    
    ...
    $result = db_query_range("SELECT uid, name FROM {users} WHERE status=1 AND uid>=%d ORDER BY uid", $start, 0, $limit);

Best regards, Alexander Pavlov.

CommentFileSizeAuthor
#5 realname-927586-5.patch906 bytesgapple
#1 realname-927586-1.patch922 bytesgapple

Comments

gapple’s picture

Title: Wrong algorithm to calculate last reindexed user » Search indexing doesn't order user results, potentially skipping users
Version: 6.x-1.3 » 6.x-1.x-dev
Status: Active » Needs review
Issue tags: +sql
StatusFileSize
new922 bytes

Rolled into a patch

gapple’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

RTBC, since I just created the patch from @avpavlov's code snippets. Simple and logical fix.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, realname-927586-1.patch, failed testing.

gapple’s picture

StatusFileSize
new906 bytes

Wasn't expecting testbot here...

Here's a patch with UNIX line endings for testbot.

gapple’s picture

Status: Needs work » Reviewed & tested by the community

status...

dave reid’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the patch. Committed as a part of http://drupal.org/cvs?commit=442626

Status: Fixed » Closed (fixed)
Issue tags: -search, -sql

Automatically closed -- issue fixed for 2 weeks with no activity.