Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services/horizon: Limit time range to max of number of buckets in trades aggregation query #2856

Merged
merged 4 commits into from
Jul 30, 2020

Conversation

bartekn
Copy link
Contributor

@bartekn bartekn commented Jul 27, 2020

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

This commit limits time range in trade aggregations query to a maximum number of buckets limited by limit param.

Why

In #632 (comment) it was suggested that the query in trade aggregations needs to prepare buckets for entire history if start and end dates are not provided. This can be fixed because we limit number of buckets returned to a user. The code in this commit adjusts start time and end time to limit the range to the maximum range visible by the API user.

Known limitations

Will test this with horizon-cmp using past /trade_aggregations requests in staging. Testing locally is hard because it requires full history.

@bartekn bartekn requested review from tomerweller and a team July 27, 2020 21:00
@cla-bot cla-bot bot added the cla: yes label Jul 27, 2020
@bartekn bartekn merged commit 85c4f66 into stellar:master Jul 30, 2020
@bartekn bartekn deleted the improve-trade-aggregation-query branch July 30, 2020 10:26
bartekn added a commit to bartekn/go that referenced this pull request Aug 5, 2020
bartekn added a commit that referenced this pull request Aug 5, 2020
…s in trades aggregation query (#2856)" (#2893)

This reverts commit 85c4f66.

Unfortunately, the performance fix for `/trade_aggregations` in
85c4f66 does not work correctly if
there were no trades for the requested market, range and resolution
within a given limit (i.e. no data in a bucket in a range).

As an example, consider a market with no trades on weekends and the
following params:
- `start_time` = Monday, 1st day of the month (for simplicity),
- `end_time` = Sunday, 14th,
- `resolution` = 1 day,
- `limit` = 7 days.

Before 85c4f66 Horizon returned 7
buckets for each day: Monday-Friday and Monday, Tuesday the following
week. With 85c4f66 it returns just 5
buckets because the `end_time` would be overwritten to EOD, Sunday, 7th.
This code works great when all buckets in the range are non-empty,
however, if there's at least one empty bucket it will return less than
`limit `buckets.
paulbellamy pushed a commit to paulbellamy/stellar-go that referenced this pull request May 6, 2021
…f buckets in trades aggregation query (stellar#2856)" (stellar#2893)"

This reverts commit cdb9959.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants