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

Proper offers pagination, account offers #154

Merged
merged 9 commits into from
Jun 4, 2019

Conversation

charlie-wasp
Copy link
Contributor

@charlie-wasp charlie-wasp commented Apr 11, 2019

Now offers have proper cursor-based pagination too 💪 Also, accounts now have connection to offers

I played a little with union types to make forward and backward motion related properties exclusive in PagingParams type. I used custom type guard for the first time. Tell me, if it's too much TS magic 🙂


This change is Reviewable

@charlie-wasp charlie-wasp requested a review from a team as a code owner April 11, 2019 15:05
@charlie-wasp charlie-wasp mentioned this pull request Apr 15, 2019
@charlie-wasp charlie-wasp force-pushed the feature/account-offers-new branch from 482fa7a to 67ebf1b Compare April 17, 2019 11:19
@charlie-wasp charlie-wasp force-pushed the feature/account-offers-new branch from 67ebf1b to 419432f Compare April 30, 2019 13:58
@charlie-wasp charlie-wasp force-pushed the feature/account-offers-new branch 2 times, most recently from ff225ef to 351f22b Compare May 22, 2019 14:53
Copy link
Member

@nebolsin nebolsin left a comment

Choose a reason for hiding this comment

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

Reviewed 16 of 16 files at r1.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @charlie-wasp)


src/model/offer.ts, line 47 at r1 (raw file):

  public get paging_token() {
    return this.id;
  }

And do we need Offer model now that we have Offer entity?


src/orm/entities/offer.ts, line 39 at r1 (raw file):

  public get paging_token() {
    return this.id;

I think default ordering for top-level offers query is (price, id) so paging token should include price component in this case. We still want ordering by id only for account { offers } queries.


src/orm/repository/offer.ts, line 17 at r1 (raw file):

      .where("offers.selling = :selling", { selling })
      .andWhere("offers.buying = :buying", { buying })
      .getRawOne();

Ordering by price and selecting the first row would guarantee that we hit the index


src/schema/offers.ts, line 71 at r1 (raw file):

      seller: AccountID
      selling: AssetCode
      buying: AssetCode

I think it would be reasonable to make selling and buying mandatory for top-level offers query, and also remove seller parameter here since it could now be queried as account { offers }.


src/schema/resolvers/offer.ts, line 93 at r1 (raw file):

      }

      return makeConnection<Offer>(await paginate(qb, paging, "offers.id"));

To reiterate, I think seller is not necessary here, selling and buying are required and default sorting should be (price, id).


src/schema/resolvers/trades.ts, line 20 at r1 (raw file):

  const offers = await getRepository(Offer).findByIds(ids);

  return ids.map(id => offers.find(o => o.id === id) || null);

This likely won't work because quite often after a trade have already happened, the offers would no longer exist in the database. Probably for now the best solution is to just return the offer ids in trades, without links to the actual offers.

@charlie-wasp charlie-wasp requested a review from nebolsin May 23, 2019 08:30
Copy link
Contributor Author

@charlie-wasp charlie-wasp left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @charlie-wasp and @nebolsin)


src/model/offer.ts, line 47 at r1 (raw file):

Previously, nebolsin (Sergey Nebolsin) wrote…

And do we need Offer model now that we have Offer entity?

Definitely no! Simply forgot about it

Copy link
Contributor Author

@charlie-wasp charlie-wasp left a comment

Choose a reason for hiding this comment

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

Reviewable status: 12 of 22 files reviewed, 6 unresolved discussions (waiting on @charlie-wasp and @nebolsin)


src/orm/entities/offer.ts, line 39 at r1 (raw file):

Previously, nebolsin (Sergey Nebolsin) wrote…

I think default ordering for top-level offers query is (price, id) so paging token should include price component in this case. We still want ordering by id only for account { offers } queries.

Working


src/orm/repository/offer.ts, line 17 at r1 (raw file):

Previously, nebolsin (Sergey Nebolsin) wrote…

Ordering by price and selecting the first row would guarantee that we hit the index

Working


src/schema/offers.ts, line 71 at r1 (raw file):

Previously, nebolsin (Sergey Nebolsin) wrote…

I think it would be reasonable to make selling and buying mandatory for top-level offers query, and also remove seller parameter here since it could now be queried as account { offers }.

Done


src/schema/resolvers/offer.ts, line 93 at r1 (raw file):

Previously, nebolsin (Sergey Nebolsin) wrote…

To reiterate, I think seller is not necessary here, selling and buying are required and default sorting should be (price, id).

Working


src/schema/resolvers/trades.ts, line 20 at r1 (raw file):

Previously, nebolsin (Sergey Nebolsin) wrote…

This likely won't work because quite often after a trade have already happened, the offers would no longer exist in the database. Probably for now the best solution is to just return the offer ids in trades, without links to the actual offers.

Done

Copy link
Contributor Author

@charlie-wasp charlie-wasp left a comment

Choose a reason for hiding this comment

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

Reviewable status: 12 of 22 files reviewed, 6 unresolved discussions (waiting on @charlie-wasp and @nebolsin)


src/orm/repository/offer.ts, line 17 at r1 (raw file):

Previously, charlie-wasp (Timur Ramazanov) wrote…

Working

Hmm, I ran explain select min(price) as min_price from offers where sellingasset = 'AAAAAU1PQkkAAAAAPHEwK55l2uMBECcQxzsOUsAWg1YwXwD+ZUTDWZEbZWQ=' and buyingasset = 'AAAAAA==', and it seems that index is used already. It says -> Index Only Scan using bestofferindex on offers (cost=0.41..597.64 rows=546 width=8)

Copy link
Contributor Author

@charlie-wasp charlie-wasp left a comment

Choose a reason for hiding this comment

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

Reviewable status: 10 of 23 files reviewed, 6 unresolved discussions (waiting on @charlie-wasp and @nebolsin)


src/orm/entities/offer.ts, line 39 at r1 (raw file):

Previously, charlie-wasp (Timur Ramazanov) wrote…

Working

Done.


src/schema/resolvers/offer.ts, line 93 at r1 (raw file):

Previously, charlie-wasp (Timur Ramazanov) wrote…

Working

Done.

Copy link
Member

@nebolsin nebolsin left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 13 of 13 files at r2.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @charlie-wasp)

@charlie-wasp charlie-wasp force-pushed the feature/account-offers-new branch from 28e7894 to bfa45aa Compare June 4, 2019 09:38
@charlie-wasp charlie-wasp force-pushed the feature/account-offers-new branch from f2b06cd to 930b797 Compare June 4, 2019 13:13
@charlie-wasp charlie-wasp merged commit d3a843e into master Jun 4, 2019
@charlie-wasp charlie-wasp deleted the feature/account-offers-new branch June 4, 2019 13:21
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