couchdb icon indicating copy to clipboard operation
couchdb copied to clipboard

Avoid read docs twice when filtered `_changes` is triggered

Open jiahuili430 opened this issue 1 year ago • 5 comments

Overview

  • When filered _changes is triggered, open_revs() will read docs. If request parameter has include_docs=true, then doc_member() will also read docs.

Change filter/3 to filter/5 to avoid the above behavior.

  • When using filtered _changes with style=all_docs, conflicts=true and include_docs=true, the response should contain the _conflicts field.

Add open_all_revs_include_doc/2 to include this field.

  • Add tests to verify the number of calls to open_doc/3.

Testing recommendations

make eunit apps=chttpd suites=chttpd_changes_test
make eunit apps=couch suites=couch_changes_tests

Related Issues or Pull Requests

Checklist

  • [ ] Code is written and works correctly
  • [x] Changes are covered by tests
  • [ ] Any new configurable parameters are documented in rel/overlay/etc/default.ini
  • [ ] Documentation changes were made in the src/docs folder
  • [ ] Documentation changes were backported (separated PR) to affected branches

jiahuili430 avatar Nov 20 '23 16:11 jiahuili430

When filered _changes is triggered, open_rev() will increment stats. If query has include_docs=true, then doc_member() will also increase stats.

In that code path it sounds like the document is being read twice, so incrementing database_reads twice sounds correct. Of course if we could avoid the second read that would be great.

Did I misunderstand the problem?

rnewson avatar Nov 20 '23 17:11 rnewson

In that code path it sounds like the document is being read twice, so incrementing database_reads twice sounds correct. Of course if we could avoid the second read that would be great.

I'll try to avoid the second read, thanks for the review.

jiahuili430 avatar Nov 20 '23 17:11 jiahuili430

To reduce the size of the PR, wonder if it would make sense to extract the enhanced tests into a separate PR. We don't intend to change the behavior of _changes endpoint to tests could be updated first then optimize the doc loading separately.

nickva avatar Dec 06 '23 19:12 nickva

To reduce the size of the PR, wonder if it would make sense to extract the enhanced tests into a separate PR. We don't intend to change the behavior of _changes endpoint to tests could be updated first then optimize the doc loading separately.

Sure, dropped the first commit.

jiahuili430 avatar Dec 06 '23 19:12 jiahuili430

Thanks for the script, @nickva. I'll investigate more.

jiahuili430 avatar Dec 08 '23 14:12 jiahuili430