Skip to content

Commit 1416e09

Browse files
committed
Make frontend fields stateless to resolve repeating content issues.
This eliminates the concept of a store for timeline data, which was just going to the client anyway when cookie store was enabled. Instead, the entire timeline worth of content will be sent to the client. This timeline is not reliant on getting a cookie back which could have been overwritten in the client by a simultaneous request. If a reliable store for this data is found, the store concept could be reinstated. However the only reason for this would seem to be if the client could not store the whole timeline, which seems unlikely. See #1329.
1 parent f5cd0a1 commit 1416e09

File tree

3 files changed

+7
-40
lines changed

3 files changed

+7
-40
lines changed

app/controllers/frontend/contents_controller.rb

+2-7
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,14 @@ def index
2222

2323
shuffle_config = FieldConfig.get(@screen, @field, 'shuffler') || DEFAULT_SHUFFLE
2424
shuffler_klass = FrontendContentOrder.load_shuffler(shuffle_config)
25-
session_key = "frontend_#{@screen.id}_#{@screen.template.id}_#{@field.id}_#{shuffler_klass}".to_sym
2625
shuffler = nil
27-
count = 1
28-
29-
count = 20 if FieldConfig.get(@screen, @field, 'marquee') == '1'
3026

3127
run_callbacks :index do # Run plugin hooks
32-
shuffler = shuffler_klass.new(@screen, @field, @subscriptions, session[session_key])
33-
@content = shuffler.next_contents(count)
28+
shuffler = shuffler_klass.new(@screen, @field, @subscriptions)
29+
@content = shuffler.next_contents()
3430
end
3531

3632
auth! object: @content
37-
session[session_key] = shuffler.save_session()
3833

3934
begin
4035
@content.each do |c|

lib/base_shuffle.rb

+3-24
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,19 @@ class BaseShuffle
77
# @param [Screen] screen Screen showing the content.
88
# @param [Field] field Field showing the content.
99
# @param [Array<Subscription>] subscriptions All the subscriptions to use.
10-
# @param [Array<Integer>] store Array to store a timeline if needed.
1110
# @param [Hash] options Any additional options.
12-
def initialize(screen, field, subscriptions, store=[], options={})
11+
def initialize(screen, field, subscriptions, options={})
1312
@screen = screen
1413
@field = field
1514
@subscriptions = subscriptions
16-
@store = store
1715
@options = options
18-
19-
@store = [] if @store.nil?
2016
end
2117

2218
# Return the next set content to be shown.
2319
#
24-
# @param [Integer] count Number of content needed, defaults to 1.
2520
# @return [Array<Content>] Next content that should be rendered.
26-
def next_contents(count=1)
27-
if @store.length < count
28-
content = content()
29-
@store += content.collect{|c| c.id}
30-
end
31-
return [] if @store.empty?
32-
33-
content_ids = @store.shift(count)
34-
Content.where(id: content_ids).to_a.compact
35-
end
36-
37-
# Return a timeline to be saved.
38-
# Since we can't directly access the session, the controller
39-
# will pull here for what should be saved.
40-
#
41-
# @return [Array<Integer>] Array of content ids in the timeline.
42-
def save_session()
43-
@store
21+
def next_contents()
22+
content.to_a.compact
4423
end
4524

4625
private

lib/weighted_shuffle.rb

+2-9
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,8 @@
66
# then jumbled up and served from a timeline.
77
class WeightedShuffle < BaseShuffle
88

9-
def next_contents(count=1)
10-
if @store.length < count
11-
content = weighted_content()
12-
@store += content.collect{|c| c.id}
13-
end
14-
return [] if @store.empty?
15-
16-
content_ids = @store.shift(count)
17-
Content.where(id: content_ids).to_a.compact
9+
def next_contents()
10+
weighted_content.to_a.compact
1811
end
1912

2013
private

0 commit comments

Comments
 (0)