sentiero-rails 1.0.0.alpha1 → 1.0.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sentiero/rails/store.rb +33 -10
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f0f5a8e4a39699bb20d9dda091a89f17f638cc10eb8fb3d26fdde59814a8e22e
|
|
4
|
+
data.tar.gz: 5f7c1f9aee0fc818757789474a8ca40cc47fd8b7b40fe45185dbf388615cdd84
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9b996051bfb56885f7a411b2edb75eda5606e32a3f5ddcbdd360bfbdbc8a7fb6ba16be9c9f36c918c37e5c4ef686224db8d9745a2edaf7b26c1ce41883dc21e0
|
|
7
|
+
data.tar.gz: 064e76cdd2bfa871b9370c504ac6b59dd657a9887bc1a71e7f6b9f25ff19d13f57102ac7289ba72274e408245397cc10ee202af771e3d46df426a6d9e540f115
|
data/lib/sentiero/rails/store.rb
CHANGED
|
@@ -44,8 +44,10 @@ module Sentiero
|
|
|
44
44
|
|
|
45
45
|
# Batched scan: one events query for the whole session page instead of the
|
|
46
46
|
# base's get_session + get_events per window.
|
|
47
|
-
def each_session_events(limit: nil, since: nil, until_time: nil)
|
|
48
|
-
|
|
47
|
+
def each_session_events(limit: nil, since: nil, until_time: nil, types: nil)
|
|
48
|
+
unless block_given?
|
|
49
|
+
return enum_for(:each_session_events, limit: limit, since: since, until_time: until_time, types: types)
|
|
50
|
+
end
|
|
49
51
|
|
|
50
52
|
cap = limit || limits.analytics_max_scan_sessions
|
|
51
53
|
summaries = list_sessions(limit: cap, since: since, until_time: until_time)
|
|
@@ -53,14 +55,29 @@ module Sentiero
|
|
|
53
55
|
|
|
54
56
|
events = events_by_session_window(summaries.map { |summary| summary[:session_id] })
|
|
55
57
|
summaries.each do |summary|
|
|
56
|
-
|
|
58
|
+
windows = events[summary[:session_id]] || {}
|
|
59
|
+
summary = summary.merge(
|
|
60
|
+
window_starts: windows.transform_values { |window_events| window_events.first&.fetch("timestamp", nil) }
|
|
61
|
+
)
|
|
62
|
+
windows.each do |window_id, window_events|
|
|
63
|
+
window_events = window_events.select { |event| types.include?(event["type"]) } if types
|
|
57
64
|
yield summary, window_id, window_events
|
|
58
65
|
end
|
|
59
66
|
end
|
|
60
67
|
end
|
|
61
68
|
|
|
62
|
-
def list_sessions(limit:, offset: 0, since: nil, until_time: nil, sort_by: nil, search: nil
|
|
69
|
+
def list_sessions(limit:, offset: 0, since: nil, until_time: nil, sort_by: nil, search: nil,
|
|
70
|
+
min_duration_ms: nil, min_events: nil)
|
|
63
71
|
scope = filtered_session_scope(since:, until_time:, search:)
|
|
72
|
+
if sort_by == "event_count" || min_duration_ms || min_events
|
|
73
|
+
scope = with_event_aggregates(scope)
|
|
74
|
+
end
|
|
75
|
+
if min_events
|
|
76
|
+
scope = scope.having("COUNT(#{Event.table_name}.id) >= ?", min_events)
|
|
77
|
+
end
|
|
78
|
+
if min_duration_ms
|
|
79
|
+
scope = scope.having("MAX(#{Event.table_name}.timestamp) - MIN(#{Event.table_name}.timestamp) >= ?", min_duration_ms)
|
|
80
|
+
end
|
|
64
81
|
scope = ordered_session_scope(scope, sort_by)
|
|
65
82
|
|
|
66
83
|
sessions = scope.offset(offset).limit(limit).to_a
|
|
@@ -370,22 +387,22 @@ module Sentiero
|
|
|
370
387
|
|
|
371
388
|
if search && !search.empty?
|
|
372
389
|
pattern = "%#{search}%"
|
|
390
|
+
table = Session.table_name
|
|
373
391
|
scope = if metadata_column?
|
|
374
|
-
scope.where("session_id LIKE ? OR CAST(metadata AS TEXT) LIKE ?", pattern, pattern)
|
|
392
|
+
scope.where("#{table}.session_id LIKE ? OR CAST(#{table}.metadata AS TEXT) LIKE ?", pattern, pattern)
|
|
375
393
|
else
|
|
376
|
-
scope.where("session_id LIKE ?", pattern)
|
|
394
|
+
scope.where("#{table}.session_id LIKE ?", pattern)
|
|
377
395
|
end
|
|
378
396
|
end
|
|
379
397
|
|
|
380
398
|
scope
|
|
381
399
|
end
|
|
382
400
|
|
|
401
|
+
# The COUNT ordering relies on the events join/group that list_sessions
|
|
402
|
+
# applies via with_event_aggregates.
|
|
383
403
|
def ordered_session_scope(scope, sort_by)
|
|
384
404
|
if sort_by == "event_count"
|
|
385
|
-
scope
|
|
386
|
-
.joins("LEFT JOIN #{Event.table_name} ON #{Event.table_name}.session_id = #{Session.table_name}.session_id")
|
|
387
|
-
.group("#{Session.table_name}.id")
|
|
388
|
-
.order(Arel.sql("COUNT(#{Event.table_name}.id) DESC"))
|
|
405
|
+
scope.order(Arel.sql("COUNT(#{Event.table_name}.id) DESC"))
|
|
389
406
|
else
|
|
390
407
|
sort_column = case sort_by
|
|
391
408
|
when "created_at" then :created_at
|
|
@@ -395,6 +412,12 @@ module Sentiero
|
|
|
395
412
|
end
|
|
396
413
|
end
|
|
397
414
|
|
|
415
|
+
def with_event_aggregates(scope)
|
|
416
|
+
scope
|
|
417
|
+
.joins("LEFT JOIN #{Event.table_name} ON #{Event.table_name}.session_id = #{Session.table_name}.session_id")
|
|
418
|
+
.group("#{Session.table_name}.id")
|
|
419
|
+
end
|
|
420
|
+
|
|
398
421
|
def window_ids_for(session_ids)
|
|
399
422
|
Event.where(session_id: session_ids)
|
|
400
423
|
.distinct.pluck(:session_id, :window_id)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sentiero-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.0.
|
|
4
|
+
version: 1.0.0.beta1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stephen Ierodiaconou
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 1.0.0.
|
|
18
|
+
version: 1.0.0.beta1
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 1.0.0.
|
|
25
|
+
version: 1.0.0.beta1
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: railties
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|