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

feat: tp is published and is approved #378

Merged
merged 32 commits into from
Jan 24, 2022
Merged

Conversation

nicosantangelo
Copy link
Contributor

@nicosantangelo nicosantangelo commented Jan 3, 2022

Closes #277
Closes #368

@coveralls
Copy link

coveralls commented Jan 10, 2022

Pull Request Test Coverage Report for Build 1740886696

  • 218 of 264 (82.58%) changed or added relevant lines in 16 files are covered.
  • 6 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.3%) to 65.793%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/Collection/Collection.service.ts 24 26 92.31%
src/Item/Item.model.ts 0 2 0.0%
src/ethereum/api/Bridge.ts 48 50 96.0%
src/Collection/Collection.router.ts 14 18 77.78%
src/Item/Item.router.ts 22 31 70.97%
src/ethereum/api/thirdParty.ts 20 32 62.5%
src/Item/Item.service.ts 42 57 73.68%
Files with Coverage Reduction New Missed Lines %
src/ethereum/api/Bridge.ts 2 84.8%
src/RequestParameters/RequestParameters.ts 4 7.32%
Totals Coverage Status
Change from base Build 1708311000: -0.3%
Covered Lines: 1998
Relevant Lines: 2888

💛 - Coveralls

@nicosantangelo nicosantangelo marked this pull request as ready for review January 11, 2022 00:04
@@ -76,77 +89,204 @@ const getThirdPartyItemQuery = () => gql`
${thirdPartyItemFragment()}
`

const getLastItemQuery = () => gql`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const getLastItemQuery = () => gql`
const getLastReviewedItemQuery = () => gql`

import { MigrationBuilder } from 'node-pg-migrate'
import { CollectionCuration } from '../src/Curation/CollectionCuration'

export const up = (pgm: MigrationBuilder) => {
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor Author

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 },
Copy link
Contributor

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.

spec/utils.ts Show resolved Hide resolved
Comment on lines +20 to +37
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
Copy link
Contributor

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.

Suggested change
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)

Copy link
Contributor Author

@nicosantangelo nicosantangelo Jan 18, 2022

Choose a reason for hiding this comment

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

I purposefully awaited 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?

Copy link
Contributor

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.

src/Item/Item.router.ts Show resolved Hide resolved
src/Item/Item.service.ts Outdated Show resolved Hide resolved
src/Collection/Collection.service.ts Outdated Show resolved Hide resolved
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', () => {
Copy link
Contributor

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:

Suggested change
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, () => {

Comment on lines +208 to +212
await this.insertCuration(
item.collection_id,
ethAddress,
CurationType.COLLECTION
)
Copy link
Contributor

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.

Copy link
Contributor Author

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


/**
* 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* 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

}

/**
* Merges the remote data, which comes from the blockchain, and the catalyst data (if it exists) *into* the db data
Copy link
Contributor

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:

Suggested change
* 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(
Copy link
Contributor

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)
Copy link
Contributor

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).

@nicosantangelo nicosantangelo merged commit 9a0e31d into master Jan 24, 2022
@nicosantangelo nicosantangelo deleted the feat/tpw-is-published branch January 24, 2022 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants