-
Notifications
You must be signed in to change notification settings - Fork 11
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
Conversation
482fa7a
to
67ebf1b
Compare
67ebf1b
to
419432f
Compare
ff225ef
to
351f22b
Compare
There was a problem hiding this 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.
There was a problem hiding this 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
There was a problem hiding this 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 foraccount { 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
andbuying
mandatory for top-level offers query, and also removeseller
parameter here since it could now be queried asaccount { 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
andbuying
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
There was a problem hiding this 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)
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 13 of 13 files at r2.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @charlie-wasp)
28e7894
to
bfa45aa
Compare
f2b06cd
to
930b797
Compare
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](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)