Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.

Refactor the notification validation, retrieval - #209

Merged
james-martin-jd merged 2 commits into
developfrom
bug/notification-performance
Apr 1, 2020
Merged

Refactor the notification validation, retrieval#209
james-martin-jd merged 2 commits into
developfrom
bug/notification-performance

Conversation

@james-martin-jd

Copy link
Copy Markdown
Contributor
  • Upgraded to latest shexjs/core version
  • Revamped the shexjs code so it is no longer looping over each file sequentially
  • Made updates so the shex code returns a list of valid data's quads
  • Updated the parsing code so it no longer re-fetches the code
  • Renamed solidLDFlex to data so it is more in line with code samples of ldflex package

* Upgraded to latest shexjs/core version
* Revamped the shexjs code so it is no longer looping over each file sequentially
* Made updates so the shex code returns a list of valid data's quads
* Updated the parsing code so it no longer re-fetches the code
* Renamed solidLDFlex to data so it is more in line with code samples of ldflex package

@Vinnl Vinnl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Now that's what I call a proper commit message, thanks :)

Comment thread src/lib/utils/shex.js Outdated
Comment on lines 330 to 336
results.forEach(resultItem => {
if (resultItem.status === 'conformant') {
const proofStore = new N3.Store();
Util.getProofGraph(resultItem.appinfo, proofStore, N3.DataFactory);
validQuads = [...validQuads, proofStore.getQuads()];
}
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not a biggie so no need to change it, but as a suggestion for future code: using map and filter there's no need to initialise an empty array at the top, and to keep concatenating arrays (validQuads = [...validQuads, proofStore.getQuads()]):

Suggested change
results.forEach(resultItem => {
if (resultItem.status === 'conformant') {
const proofStore = new N3.Store();
Util.getProofGraph(resultItem.appinfo, proofStore, N3.DataFactory);
validQuads = [...validQuads, proofStore.getQuads()];
}
});
results
.filter(resultItem => resultItem.status === 'conformant')
.map(resultItem => {
const proofStore = new N3.Store();
Util.getProofGraph(resultItem.appinfo, proofStore, N3.DataFactory);
return proofStore.getQuads();
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can try your suggested code out.

Originally this WAS done with .map, then .reduce. I worked with another dev (a ShEx expert) on this part of the code, but the .reduce wasn't working properly and was causing unexpected behavior.

For now, I went with a simpler, old fashioned method to get it working. I can try again with your .map and see if it works as expected now that reduce (and some of the strange internal code) has been updated and fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could, but don't spend too much time on it. In any case it's a fine line to thread, and especially reduce can easily lead to code becoming less easy to follow. In this case it's almost a toin coss, IMHO.

@james-martin-jd james-martin-jd changed the title Refactor the notification valiidation, retrieval Refactor the notification validation, retrieval Apr 1, 2020
* Refactored out the .foreach for a map/filter combo
* Added additional commenting to make the code clearer to newcomers
@james-martin-jd
james-martin-jd requested a review from Vinnl April 1, 2020 13:38
@james-martin-jd
james-martin-jd merged commit 0663691 into develop Apr 1, 2020
@james-martin-jd
james-martin-jd deleted the bug/notification-performance branch April 1, 2020 14:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants