-
Notifications
You must be signed in to change notification settings - Fork 79
remove subscriptions sync if timeout is zero, to preserve add/remove call order #9
base: master
Are you sure you want to change the base?
Conversation
…remove call order
@@ -84,19 +84,6 @@ - (METSubscription *)addSubscriptionWithName:(NSString *)name parameters:(NSArra | |||
return subscription; | |||
} | |||
|
|||
- (METSubscription *)existingSubscriptionWithName:(NSString *)name parameters:(NSArray *)parameters { |
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 is just moved below into the Helpers section
@martijnwalraven what do you think? |
I remember considering it a feature not to unsubscribe immediately even with a timeout of 0, because other parts of the app might add the same subscription within the current run loop cycle and it would be a waste to unnecessarily unsubscribe and subscribe again. I'm ok with making this change because you can always set the notInUseTimeout > 0 to get reuse behavior back. But just out of curiosity, why do you require an |
It may seem unusual but our search feature is built reactively. This is done in such a way that we use temporary collections of data to hold results to subscriptions. We are almost emulating a method call with a subscription, so that we can react to changes after the call is made. We are using subscriptions in a fairly non traditional way, but i think it is pushing the limits of what can be achieved, with less code running client side for complicated things like search. In the UI the a complicated search query can be created, with searchTerm, location w/ distance sort, sort by , and various filters. The client the subscribes to pages of results:
Search results are then published to a collection called
At any given time, the jobSearchResults array must contain ONLY results of the current search query. We use this collection to allow the client to reactively see changes to their results without having to support all filters locally by observing changes to that collection as a whole. If a new job was added, within your location vicinity, or unpublished, ddp will inform us, but removing the job from the When the query changes, we unsubscribe to all pages of the previous query, and wait for Before my change, if the search results for the new query were added before, the old one was removed, the user would see the results from both searches simultaneously for a short period of time. |
There is probably a way to support both what you want, reuse if resubscribed during the same run loop, and immediate unsub as we desire. Ideally, there needs to be a lower level subscriptions API that is not limited by the logic of METSubscriptionManager so we can achieve more non-traditional features like ours. ObjectiveDDP provides only this lower level API and intelligent management of subs is limited. Perhaps your library is not intended for more custom uses like ours? How do you envision it being used? Another possibility is there can be a separate flag besides the notInUseTimeout property to determine if a particular subscription should be Any ideas on this stuff? |
Ah, no I understand where this is coming from. The search subscription seems like a pretty neat solution for live results updates. Another way to avoid mixing up results might be to include some kind of queryId in jobSearchResults documents so you can filter them on the client. That wouldn't require an immediate unsub and would also make it possible to run multiple concurrent live queries. That would require changes on the server though. I'm a bit preoccupied with another project right now, so I haven't thought this through, but it seems what you're looking for is a way to add a subscription that is never shared and reused (and so can be unsubscribed immediately). I'm not sure about a lower level API because METSubscriptionManager is also responsible for reviving subscriptions after reconnect. But perhaps an |
We have a few features that require
unsub
messages to be sent over the wire beforesub
message to the same subscription, with different parameters. Even with a timeout of zero, in the current code on master branch, theunsub
would go after thesub
.This is caused by the following:
if the
METSubscriptionManager
was configured with a default timeout of 0, or theMETSubscription
had a timeout configured of zero, the call toremoveSubscription
would actually cause the remove to happen after[subscription.reuseTimer startWithTimeInterval:subscription.notInUseTimeout];
. Even with timeout 0 thesub
for subscription 2 would happen first.