From e5419f5ed7e4ac1748b33cdd16965d8b5e22308b Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 28 Feb 2016 22:43:57 -0500 Subject: [PATCH 1/5] remove queries from channel_live_queries when they are no longer associated with a channel --- app/volt/tasks/live_query/live_query.rb | 2 +- app/volt/tasks/query_tasks.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/volt/tasks/live_query/live_query.rb b/app/volt/tasks/live_query/live_query.rb index 2b3ef2c9..2b53fdf0 100644 --- a/app/volt/tasks/live_query/live_query.rb +++ b/app/volt/tasks/live_query/live_query.rb @@ -3,7 +3,7 @@ # Tracks a channel and a query on a collection. Alerts # the listener when the data in the query changes. class LiveQuery - attr_reader :current_ids, :collection, :query + attr_reader :current_ids, :collection, :query, :channels def initialize(pool, data_store, collection, query) @pool = pool diff --git a/app/volt/tasks/query_tasks.rb b/app/volt/tasks/query_tasks.rb index 6a9b0d1b..c80706ae 100644 --- a/app/volt/tasks/query_tasks.rb +++ b/app/volt/tasks/query_tasks.rb @@ -45,6 +45,9 @@ def initial_data def remove_listener(collection, query) live_query = @volt_app.live_query_pool.lookup(collection, query) live_query.remove_channel(@channel) + + # If query has no more channels remove it from channel_live_queries + @volt_app.channel_live_queries[@channel].delete(live_query) if live_query.channels.blank? end # Removes a channel from all associated live queries From 97b4abca1852d8d4d735d63bc2e23c4414ed83ac Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 28 Feb 2016 23:26:52 -0500 Subject: [PATCH 2/5] checking if serialize errors are from this delete --- app/volt/tasks/query_tasks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/volt/tasks/query_tasks.rb b/app/volt/tasks/query_tasks.rb index c80706ae..0be756a8 100644 --- a/app/volt/tasks/query_tasks.rb +++ b/app/volt/tasks/query_tasks.rb @@ -47,7 +47,7 @@ def remove_listener(collection, query) live_query.remove_channel(@channel) # If query has no more channels remove it from channel_live_queries - @volt_app.channel_live_queries[@channel].delete(live_query) if live_query.channels.blank? + # @volt_app.channel_live_queries[@channel].delete(live_query) if live_query.channels.blank? end # Removes a channel from all associated live queries From d97ee8f245fa68ea2d313a8a4d0f10a2f32419d9 Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 28 Feb 2016 23:36:59 -0500 Subject: [PATCH 3/5] can't do delete on the query object. instead loop through the channel live queries looking for ones with no more channels --- app/volt/tasks/query_tasks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/volt/tasks/query_tasks.rb b/app/volt/tasks/query_tasks.rb index 0be756a8..7247f08d 100644 --- a/app/volt/tasks/query_tasks.rb +++ b/app/volt/tasks/query_tasks.rb @@ -47,7 +47,7 @@ def remove_listener(collection, query) live_query.remove_channel(@channel) # If query has no more channels remove it from channel_live_queries - # @volt_app.channel_live_queries[@channel].delete(live_query) if live_query.channels.blank? + @volt_app.channel_live_queries[@channel].delete_if{|channel_live_query| channel_live_query.channels.blank? } end # Removes a channel from all associated live queries From be023b8239d7cb90f692833436a502ed26912f2f Mon Sep 17 00:00:00 2001 From: mike Date: Mon, 29 Feb 2016 02:21:44 -0500 Subject: [PATCH 4/5] return true when running remove listener to provide a return value that's easily serializable. --- app/volt/tasks/query_tasks.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/volt/tasks/query_tasks.rb b/app/volt/tasks/query_tasks.rb index 7247f08d..81146237 100644 --- a/app/volt/tasks/query_tasks.rb +++ b/app/volt/tasks/query_tasks.rb @@ -47,7 +47,8 @@ def remove_listener(collection, query) live_query.remove_channel(@channel) # If query has no more channels remove it from channel_live_queries - @volt_app.channel_live_queries[@channel].delete_if{|channel_live_query| channel_live_query.channels.blank? } + @volt_app.channel_live_queries[@channel].delete(live_query) if live_query.channels.blank? unless RUBY_PLATFORM == 'opal' + return true end # Removes a channel from all associated live queries From 214ab96e32511c40b0c1f61cbb9f38b10577c7f1 Mon Sep 17 00:00:00 2001 From: mike Date: Mon, 29 Feb 2016 02:25:05 -0500 Subject: [PATCH 5/5] don't need to check for opal from the task --- app/volt/tasks/query_tasks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/volt/tasks/query_tasks.rb b/app/volt/tasks/query_tasks.rb index 81146237..c356109d 100644 --- a/app/volt/tasks/query_tasks.rb +++ b/app/volt/tasks/query_tasks.rb @@ -47,7 +47,7 @@ def remove_listener(collection, query) live_query.remove_channel(@channel) # If query has no more channels remove it from channel_live_queries - @volt_app.channel_live_queries[@channel].delete(live_query) if live_query.channels.blank? unless RUBY_PLATFORM == 'opal' + @volt_app.channel_live_queries[@channel].delete(live_query) if live_query.channels.blank? return true end