-
Notifications
You must be signed in to change notification settings - Fork 17
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
feat: tp is published and is approved #378
Conversation
…er-server into feat/tpw-is-published
Pull Request Test Coverage Report for Build 1740886696
💛 - Coveralls |
16b7689
to
f862202
Compare
src/ethereum/api/thirdParty.ts
Outdated
@@ -76,77 +89,204 @@ const getThirdPartyItemQuery = () => gql` | |||
${thirdPartyItemFragment()} | |||
` | |||
|
|||
const getLastItemQuery = () => gql` |
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.
const getLastItemQuery = () => gql` | |
const getLastReviewedItemQuery = () => gql` |
import { MigrationBuilder } from 'node-pg-migrate' | ||
import { CollectionCuration } from '../src/Curation/CollectionCuration' | ||
|
||
export const up = (pgm: MigrationBuilder) => { |
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.
This should be already complete in #378
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.
Isn't #378 this PR?
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.
Oh! #379 right? I think this and the migration slipped thru the rebase
item_id: { type: 'UUID', notNull: true }, | ||
status: { type: 'CURATION_STATUS', notNull: true }, | ||
created_at: { type: 'TIMESTAMP', notNull: true }, | ||
updated_at: { type: 'TIMESTAMP', notNull: true }, |
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.
If I'm not wrong, this has already been created in #378.
const collections: CollectionAttributes[] = [] | ||
|
||
for (const dbCollection of dbCollections) { | ||
let fullCollection: CollectionAttributes = { ...dbCollection } | ||
|
||
if (isTPCollection(dbCollection)) { | ||
const lastItem = await thirdPartyAPI.fetchLastItem( | ||
dbCollection.third_party_id, | ||
dbCollection.urn_suffix | ||
) | ||
if (lastItem) { | ||
fullCollection = Bridge.mergeTPCollection(dbCollection, lastItem) | ||
} | ||
} | ||
|
||
collections.push(fullCollection) | ||
} | ||
return collections |
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.
Having this async operation inside the for loop will make this "synchronous", possibly taking a long time to process all of the collections. There's also a problem if we do it all asynchronous, and that is that we need to rate limit the requests, but we can leave this to another PR.
const collections: CollectionAttributes[] = [] | |
for (const dbCollection of dbCollections) { | |
let fullCollection: CollectionAttributes = { ...dbCollection } | |
if (isTPCollection(dbCollection)) { | |
const lastItem = await thirdPartyAPI.fetchLastItem( | |
dbCollection.third_party_id, | |
dbCollection.urn_suffix | |
) | |
if (lastItem) { | |
fullCollection = Bridge.mergeTPCollection(dbCollection, lastItem) | |
} | |
} | |
collections.push(fullCollection) | |
} | |
return collections | |
const promiseOfCollections: Promise<CollectionAttributes[]> = [] | |
promiseOfCollections = dbCollections.map(() => { | |
let fullCollection: CollectionAttributes = { ...dbCollection } | |
if (isTPCollection(dbCollection)) { | |
const lastItem = await thirdPartyAPI.fetchLastItem( | |
dbCollection.third_party_id, | |
dbCollection.urn_suffix | |
) | |
if (lastItem) { | |
fullCollection = Bridge.mergeTPCollection(dbCollection, lastItem) | |
} | |
} | |
}) | |
return Promise.all(promiseOfCollections) |
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.
I purposefully await
ed inside the for loop for the rate limit problem. My thought process was:
- I need to do this in parallel
- I should batch
- There's no native batch solution
- Implementing or installing one would make this PR even bigger
- It sounds better to have a slow endpoint than a broken one
What do you think? do you prefer to go with the Promise.all
directly?
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.
We can leave it as it for the moment, but we should tackle this issue in the near future.
url = `/collections/${dbCollectionMock.id}/items` | ||
}) | ||
|
||
it('should return all the items of a collection that are published with URN and the ones that are not without 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.
As the TP items must contain the URN:
it('should return all the items of a collection that are published with URN and the ones that are not without it', () => { | |
it('should return all the items of a collection that are published with their URN, () => { |
await this.insertCuration( | ||
item.collection_id, | ||
ethAddress, | ||
CurationType.COLLECTION | ||
) |
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.
Maybe we could create a trigger in the DB to do this, but it's just something to think about.
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.
Agree it could be much better. Triggers sometime make me uncomfortable as they're "hidden" logic that's super hard to debug in production tho. But we could check it out
src/ethereum/api/Bridge.ts
Outdated
|
||
/** | ||
* Merges the remote data, which comes from the blockchain, and the catalyst data (if it exists) *into* the db data | ||
* The db item is first converted to a full item and then get's the appropiate data merged into 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.
* The db item is first converted to a full item and then get's the appropiate data merged into it | |
* The db item is first converted to a full item and then get the appropriate data merged into it |
src/ethereum/api/Bridge.ts
Outdated
} | ||
|
||
/** | ||
* Merges the remote data, which comes from the blockchain, and the catalyst data (if it exists) *into* the db data |
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.
What do you think about something like this:
* Merges the remote data, which comes from the blockchain, and the catalyst data (if it exists) *into* the db data | |
* Combines the remote data (item from the blockchain), the catalyst data (if it exists) and the item's DB data *into* a FullItem. |
return { dbTPItems, remoteTPItems } | ||
} | ||
|
||
public splitItems( |
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.
It seems that this JSDoc is missing.
return { item, remoteItem } | ||
}) | ||
|
||
const tpItemURNs = Object.keys(itemsByURN) |
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.
Itms by URN is an array here, so Object.keys
won't work. The map above this line should do a reduce over the dbItems to build the itemsByURN map (or record).
Closes #277
Closes #368