Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Add option of terminate_after when run a query #79

Merged
merged 3 commits into from Oct 1, 2016

Conversation

CCheSumo
Copy link
Contributor

@CCheSumo CCheSumo commented Sep 30, 2016

It turns out terminate_after can have huge impact on latency when the document counts are large.

In order to support terminate_after and maintain backward compatibility, I have to create an ExtendedQueryRoot that inherits QueryRoot. This api can serve to extend any further enhancements to QueryRoot before 2.0.

This api should be incorporated into QueryRoot in 2.0 when breaking changes are allowed.

@CCheSumo
Copy link
Contributor Author

@rcoh PR for enabling terminate_after when running a query.

@codecov-io
Copy link

codecov-io commented Sep 30, 2016

Current coverage is 61.04% (diff: 73.33%)

Merging #79 into master will increase coverage by 0.11%

@@             master        #79   diff @@
==========================================
  Files            14         14          
  Lines           906        919    +13   
  Methods           0          0          
  Messages          0          0          
  Branches        228        232     +4   
==========================================
+ Hits            552        561     +9   
- Misses          210        211     +1   
- Partials        144        147     +3   

Powered by Codecov. Last update 7e39d2c...58b18ff


// This api should be incorporated into QueryRoot in 2.0 when breaking changes are allowed.
// Before that, this api can serve to extend QueryRoot with backward compatibility.
class ExtendedQueryRoot(override val query: Query,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must be missing something. Why can't we just add terminateAfter with a default value and keep backwards compat?

Copy link
Contributor Author

@CCheSumo CCheSumo Sep 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have QueryRoot object which has an apply method that has parameters with default values. QueryRoot case class also has an apply method.

Currently, all QueryRoot case class's parameters do not have default values, which is fine.

However, if we were to add terminateAfter: Option[Int]=None, the code will not compile due to scala compiler disallowing overloaded methods with default arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right! Forgot about that bit of nastiness. If you want, you could add another optional parameter to the apply method. If terminateAfter was defined, we'd return an ExtendedQueryRoot instead. That way we hide the problem inside of the library. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Let me put in that.

@rcoh
Copy link
Contributor

rcoh commented Sep 30, 2016

OK LGTM. I made a suggestion above you can take if you want.

Seems like we're building up enough stuff to cut 2.0 soon.

@rcoh rcoh mentioned this pull request Oct 1, 2016
val sorts = sortOpt
.map(_.foldLeft(Seq.empty[Sort])((sorts, value) => sorts :+ SimpleSort(value._1, SortOrder.fromString(value._2))))
.getOrElse(Nil)
new QueryRoot(query, fromOpt, sizeOpt, sorts, timeout, sourceFilter)
if (terminateAfter.isDefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

terminateAfter
  .map(tA => new Ex....)
  .getOrElse(new Query Root....)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@CCheSumo CCheSumo merged commit bf951c0 into master Oct 1, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants