Ticket #604: mset-only-cache-fetch.patch

File mset-only-cache-fetch.patch, 1.1 KB (added by Olly Betts, 12 years ago)

proposed fix

  • api/omenquire.cc

     
    396396    if (index < firstitem || index >= firstitem + items.size()) {
    397397        throw RangeError("The mset returned from the match does not contain the document at index " + str(index));
    398398    }
    399     fetch_items(index, index); // FIXME: this checks indexeddocs AGAIN!
    400     /* Actually read the fetched documents */
    401     read_docs();
    402     Assert(indexeddocs.find(index) != indexeddocs.end());
    403     Assert(indexeddocs.find(index)->first == index); // Paranoid assert
    404     RETURN(indexeddocs.find(index)->second);
     399    Assert(enquire.get());
     400    if (!requested_docs.empty()) {
     401        // There's already a pending request, so handle that.
     402        read_docs();
     403        // Maybe we just fetched the doc we want.
     404        doc = indexeddocs.find(index);
     405        if (doc != indexeddocs.end()) {
     406            RETURN(doc->second);
     407        }
     408    }
     409
     410    // Don't cache unless fetch() was called by the API user.
     411    enquire->request_doc(items[index - firstitem]);
     412    RETURN(enquire->read_doc(items[index - firstitem]));
    405413}
    406414
    407415void