Applying staleness detection optimization to QueryDocumentIds method to ...

...be consistent with database statistics and querying results