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

removed repeatedly refetching remote pins #2105

Merged
merged 3 commits into from Mar 22, 2023

Conversation

JustinTime42
Copy link
Contributor

This fixes #2080. I can't find any reason in the current code base for why doFetchRemotePins needs to repeat continuously, and doing so causes a periodic re-render that interrupts media playback in the file preview.

@JustinTime42 JustinTime42 requested a review from a team as a code owner March 3, 2023 02:36
@JustinTime42 JustinTime42 temporarily deployed to Deploy March 3, 2023 02:40 — with GitHub Actions Inactive
@SgtPooki
Copy link
Member

@JustinTime42 thanks so much for submitting this fix. That playback bug was something I kept wanting to come back to but haven't had the chance. I will confirm the fix today and try to get this merged.

@SgtPooki SgtPooki requested a review from whizzzkid March 13, 2023 17:46
@SgtPooki
Copy link
Member

I updated the code so that we can still poll for fetch updates, but not re-render if there are no updates. This is not as performant as it could be, but it resolves the issue. Can you confirm @JustinTime42 ? Also requested a review from @whizzzkid since this is basically only my code now.

Copy link
Member

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

Self review. Not as performant as it should be, but it fixes the bug without changing much in existing code (that @hacdias spent a lot of time getting to work for remote pinning features).

Comment on lines 105 to 110
const pins = [
...store.selectPendingPins(),
...store.selectFailedPins()
].map(serviceCid => ({ cid: serviceCid.split(':')[1] }))
store.doFetchRemotePins(pins, true)
}
Copy link
Member

Choose a reason for hiding this comment

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

code seems straightforward to me. It makes sense that if this is being called every 30 seconds (PIN_CHECK_INTERVAL), that any components dependent upon doFetchRemotePins would refresh when this is called. However, if there are no updates, we shouldn't be updating the store and there should be no update.. so this continually updating means the correct fix is probably in doFetchRemotePins.

@SgtPooki SgtPooki temporarily deployed to Deploy March 13, 2023 17:50 — with GitHub Actions Inactive
Copy link
Contributor

@whizzzkid whizzzkid left a comment

Choose a reason for hiding this comment

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

mostly LGTM, nit.

*/
const getRerenderAwareArray = (oldArray, newArray) => {
if (oldArray.length !== newArray.length) return newArray
const diff = oldArray.filter((i) => !newArray.includes(i))
Copy link
Contributor

Choose a reason for hiding this comment

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

Sooo... what happens if the newArray has elements that oldArray doesn't? i.e. if the oldArray is a subset of newArray then diff would be empty?

Copy link
Member

@SgtPooki SgtPooki Mar 22, 2023

Choose a reason for hiding this comment

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

if the length different, we always return the new array.

if the length is the same, we compare content.

so in your example, oldArray is a subset, meaning length is different, meaning we return the new array

@SgtPooki SgtPooki merged commit f2bf41b into ipfs:main Mar 22, 2023
@ipfs-gui-bot
Copy link
Collaborator

🎉 This PR is included in version 3.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Playing a media (audio/video) stops after a few seconds
4 participants