parity_timeline 0.3.2 → 0.3.4
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/timeline/controller_helper.rb +39 -2
- data/lib/timeline/notification_helper.rb +2 -3
- data/lib/timeline/untitled.txt +5 -1
- data/lib/timeline/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e85146f69c8fde0197e60c17e05915a0af4412cc
|
4
|
+
data.tar.gz: 7a677ed0ec60db4aa3ecdfccdf0278e07abace4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59a011912f306bbd1dc89be69bf41c9c2180a0b1fbfe1292196cd454bf34236997a7574e58e7d94332682706ebd257ae2dba23bb03fa27cc87f8cd5de5e08b1b
|
7
|
+
data.tar.gz: 305562d0439a61010de6217c2693bb84239e9c5988a181b30026d262d68a3527a8eb1f635af1a03574e246652acf00c3f34d02064186c100fd630f770a9ca2bc
|
@@ -9,12 +9,14 @@ module Timeline
|
|
9
9
|
def track_timeline_activity(name, options={})
|
10
10
|
@name = name
|
11
11
|
@start_value = 0
|
12
|
-
@limit_records = options
|
12
|
+
@limit_records = (options[:limit_records] && options[:limit_records] > 30) ? options[:limit_records] : 30
|
13
|
+
@limit_days = (options[:limit_days] && options[:limit_days] > 30) ? options[:limit_days] : 30
|
13
14
|
@actor = options.delete :actor
|
14
15
|
@actor ||= :creator
|
15
16
|
@object = options.delete :object
|
16
17
|
@target = options.delete :target
|
17
18
|
@followers = options.delete :followers
|
19
|
+
@friends = options.delete :friends
|
18
20
|
@mentionable = options.delete :mentionable
|
19
21
|
|
20
22
|
@fields_for = {}
|
@@ -46,6 +48,7 @@ module Timeline
|
|
46
48
|
add_activity_by_user(activity_item[:actor][:id], activity_item)
|
47
49
|
add_mentions(activity_item)
|
48
50
|
add_activity_to_followers(activity_item) if @followers.any?
|
51
|
+
add_activity_to_friends(activity_item) if @friends.any?
|
49
52
|
end
|
50
53
|
|
51
54
|
def add_activity_by_user(user_id, activity_item)
|
@@ -56,10 +59,18 @@ module Timeline
|
|
56
59
|
redis_add "user:id:#{user_id}:activity", activity_item
|
57
60
|
end
|
58
61
|
|
62
|
+
def add_activity_to_users_friends(user_id, activity_item)
|
63
|
+
redis_add "user:id:#{user_id}:activity:friends", activity_item
|
64
|
+
end
|
65
|
+
|
59
66
|
def add_activity_to_followers(activity_item)
|
60
67
|
@followers.each { |follower| add_activity_to_user(follower.id, activity_item) }
|
61
68
|
end
|
62
69
|
|
70
|
+
def add_activity_to_friends(activity_item)
|
71
|
+
@friends.each { |friend| add_activity_to_users_friends(friend, activity_item) }
|
72
|
+
end
|
73
|
+
|
63
74
|
def add_mentions(activity_item)
|
64
75
|
return unless @mentionable and @object.send(@mentionable)
|
65
76
|
@object.send(@mentionable).scan(/@\w+/).each do |mention|
|
@@ -95,7 +106,33 @@ module Timeline
|
|
95
106
|
|
96
107
|
def redis_add(list, activity_item)
|
97
108
|
Timeline.redis.lpush list, Timeline.encode(activity_item)
|
98
|
-
|
109
|
+
trim_activities list
|
110
|
+
end
|
111
|
+
|
112
|
+
def trim_activities(list)
|
113
|
+
return if (Timeline.redis.llen list) < @limit_records
|
114
|
+
last_record = get_record(list, -1)
|
115
|
+
return if (last_record && last_record["created_at"]) > Time.now - @limit_days.days
|
116
|
+
trim_old_activities(list)
|
117
|
+
end
|
118
|
+
|
119
|
+
def get_record(list, index)
|
120
|
+
last_record = Timeline.redis.lindex list, index
|
121
|
+
last_record = Timeline.decode(last_record) if last_record
|
122
|
+
end
|
123
|
+
|
124
|
+
def trim_old_activities(list)
|
125
|
+
Timeline.redis.ltrim list , 0 , get_trim_index(list, (Timeline.redis.llen list) - 1)
|
126
|
+
end
|
127
|
+
|
128
|
+
def get_trim_index(list, index)
|
129
|
+
return @limit_records if index < @limit_records
|
130
|
+
record = get_record(list, index)
|
131
|
+
if record && (record["created_at"] < Time.now - @limit_days.days)
|
132
|
+
return get_trim_index(list, index - 5)
|
133
|
+
else
|
134
|
+
return index
|
135
|
+
end
|
99
136
|
end
|
100
137
|
|
101
138
|
def set_object(object)
|
@@ -21,9 +21,8 @@ module Timeline
|
|
21
21
|
|
22
22
|
def add_activity_to_subscribed_user(followers, activity_item)
|
23
23
|
followers.each do |follower|
|
24
|
-
|
25
|
-
|
26
|
-
trim_notification "user:id:#{follower_id}:notification"
|
24
|
+
add_to_redis "user:id:#{follower.id}:notification", activity_item
|
25
|
+
trim_notification "user:id:#{follower.id}:notification"
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
data/lib/timeline/untitled.txt
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
1.upto(User.last.id).each do |u|
|
2
2
|
list = "user:id:#{u}:notification"
|
3
|
-
Timeline.redis.ltrim list, 0,
|
3
|
+
Timeline.redis.ltrim list, 0, 30
|
4
|
+
list = "user:id:#{u}:posts"
|
5
|
+
Timeline.redis.ltrim list, 0, 30
|
6
|
+
list = "user:id:#{u}:activity"
|
7
|
+
Timeline.redis.ltrim list, 0, 30
|
4
8
|
end
|
data/lib/timeline/version.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parity_timeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felix Clack
|
8
8
|
- Shiva Kumar
|
9
|
-
- Jimish
|
9
|
+
- Jimish Jobanputra
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-06-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|