Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Fix issue removing subscriptions #29

Merged
merged 9 commits into from
Jul 26, 2022
Merged

Fix issue removing subscriptions #29

merged 9 commits into from
Jul 26, 2022

Conversation

neekolas
Copy link
Collaborator

@neekolas neekolas commented Jul 25, 2022

Summary

Notes

  • This PR will be re-created against the upstream main once merged

@neekolas neekolas marked this pull request as ready for review July 25, 2022 23:11
@neekolas neekolas changed the title Add failing test Fix issue removing subscriptions Jul 25, 2022
@neekolas neekolas requested a review from a team July 26, 2022 00:57
subCfs := subscriber.filter.ContentFilters
for _, cf := range subCfs {
for i, cf := range subCfs {
if cf.ContentTopic == contentFilter.ContentTopic {
l := len(subCfs) - 1
subCfs[l], subCfs[i] = subCfs[i], subCfs[l]

Choose a reason for hiding this comment

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

seems that this could just be subCfs[i] = subCfs[l] given that we're dropping subCfs[l] on the next line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right. Simplified.

Copy link

@elisealix22 elisealix22 left a comment

Choose a reason for hiding this comment

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

⚡️ Nice find and tests! Thank you for the quick fix.

if cf.ContentTopic == contentFilter.ContentTopic {
l := len(subCfs) - 1
subCfs[l], subCfs[i] = subCfs[i], subCfs[l]
subscriber.filter.ContentFilters = subCfs[:l]
}
}
sub.subscribers[subIndex] = subscriber
Copy link

@mkobetic mkobetic Jul 26, 2022

Choose a reason for hiding this comment

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

Ah, right, []Subscriber instead of []*Subscriber, it's messy when you don't use pointers. Alternative would be to set subscriber := &(sub.subscribers[subIndex]) up top, but this works too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Took me a while banging my head against the wall to notice that one...

Copy link

@mkobetic mkobetic left a comment

Choose a reason for hiding this comment

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

Good tests. 👍

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.

4 participants