tekeya 0.0.7 → 0.0.9
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.
- data/Gemfile +1 -0
- data/db/migrate/00_create_activities.rb +3 -1
- data/lib/tekeya/entity.rb +9 -3
- data/lib/tekeya/entity/group.rb +1 -1
- data/lib/tekeya/feed/activity.rb +29 -5
- data/lib/tekeya/feed/activity/item.rb +5 -5
- data/lib/tekeya/feed/activity/resque/untrack_feed.rb +1 -0
- data/lib/tekeya/feed/attachable.rb +1 -1
- data/lib/tekeya/feed/attachment.rb +2 -1
- data/lib/tekeya/feed/notification.rb +2 -1
- data/lib/tekeya/version.rb +1 -1
- data/spec/spec_helper.rb +3 -3
- data/spec/tekeya/activity_spec.rb +5 -2
- metadata +10 -10
data/Gemfile
CHANGED
@@ -4,8 +4,10 @@ class CreateActivities < ActiveRecord::Migration
|
|
4
4
|
t.string :activity_type, null: false
|
5
5
|
t.integer :entity_id, null: false
|
6
6
|
t.string :entity_type, null: false
|
7
|
+
t.integer :author_id, null: false
|
8
|
+
t.string :author_type, null: false
|
7
9
|
|
8
10
|
t.timestamps
|
9
11
|
end
|
10
12
|
end
|
11
|
-
end
|
13
|
+
end
|
data/lib/tekeya/entity.rb
CHANGED
@@ -36,7 +36,7 @@ module Tekeya
|
|
36
36
|
attachments << ::Tekeya::Attachment.new(attachable: attachable)
|
37
37
|
end
|
38
38
|
|
39
|
-
create(activity_type: meth, attachments: attachments, group_with_recent: options[:group].nil? ? true : options[:group])
|
39
|
+
create(activity_type: meth, attachments: attachments, group_with_recent: options[:group].nil? ? true : options[:group], author: options[:author])
|
40
40
|
else
|
41
41
|
super
|
42
42
|
end
|
@@ -312,13 +312,19 @@ module Tekeya
|
|
312
312
|
acts_keys = ::Tekeya.redis.zrevrange(pkey, 0, -1)
|
313
313
|
# Retrieve the aggregates
|
314
314
|
acts_keys.each do |act_key|
|
315
|
-
|
315
|
+
# Make `from_redis` only hit the db if author != entity
|
316
|
+
key_components = act_key.split(':')
|
317
|
+
actor = if key_components[4] == self.class.to_s && key_components[5] == self.entity_primary_key
|
318
|
+
self
|
319
|
+
end
|
320
|
+
|
321
|
+
acts << ::Tekeya::Feed::Activity::Item.from_redis(act_key, actor)
|
316
322
|
end
|
317
323
|
else
|
318
324
|
# Retrieve the activities from the DB
|
319
325
|
db_recent_activities = self.activities.recent
|
320
326
|
db_recent_activities.each do |activity|
|
321
|
-
acts << ::Tekeya::Feed::Activity::Item.from_db(activity,
|
327
|
+
acts << ::Tekeya::Feed::Activity::Item.from_db(activity, activity.author)
|
322
328
|
end
|
323
329
|
end
|
324
330
|
|
data/lib/tekeya/entity/group.rb
CHANGED
data/lib/tekeya/feed/activity.rb
CHANGED
@@ -5,17 +5,23 @@ module Tekeya
|
|
5
5
|
|
6
6
|
included do
|
7
7
|
belongs_to :entity, polymorphic: true, autosave: true
|
8
|
+
belongs_to :author, polymorphic: true, autosave: true
|
8
9
|
has_many :attachments, as: :attache, class_name: 'Tekeya::Attachment'
|
9
10
|
|
11
|
+
before_create do |act|
|
12
|
+
act.author ||= act.entity
|
13
|
+
end
|
10
14
|
before_create :group_activities
|
15
|
+
|
11
16
|
after_create :write_activity_in_redis
|
12
17
|
after_destroy :delete_activity_from_redis
|
13
18
|
|
14
19
|
accepts_nested_attributes_for :attachments
|
15
20
|
|
16
|
-
validates_presence_of :attachments
|
21
|
+
validates_presence_of :attachments, :activity_type
|
17
22
|
|
18
23
|
attr_writer :group_with_recent
|
24
|
+
attr_accessible :attachments, :activity_type, :author, :entity, :group_with_recent
|
19
25
|
end
|
20
26
|
|
21
27
|
# Check if this activity is cached in redis
|
@@ -40,7 +46,14 @@ module Tekeya
|
|
40
46
|
return current_time_from_proper_timezone.to_i
|
41
47
|
end
|
42
48
|
else
|
43
|
-
|
49
|
+
if from_time.present?
|
50
|
+
stamp = from_time.to_i
|
51
|
+
|
52
|
+
# floors the timestamp to the nearest 15 minute
|
53
|
+
return (stamp.to_f / 15.minutes).floor * 15.minutes
|
54
|
+
else
|
55
|
+
return Time.now.to_i
|
56
|
+
end
|
44
57
|
end
|
45
58
|
end
|
46
59
|
|
@@ -48,7 +61,16 @@ module Tekeya
|
|
48
61
|
#
|
49
62
|
# @return [String] the activity key
|
50
63
|
def activity_key
|
51
|
-
|
64
|
+
k = []
|
65
|
+
k[0] = 'activity'
|
66
|
+
k[1] = self.id
|
67
|
+
k[2] = self.entity_type
|
68
|
+
k[3] = self.entity.send(self.entity.entity_primary_key)
|
69
|
+
k[4] = self.author_type
|
70
|
+
k[5] = self.author.send(self.author.entity_primary_key)
|
71
|
+
k[6] = self.activity_type
|
72
|
+
k[7] = score(self.created_at)
|
73
|
+
k.join(':')
|
52
74
|
end
|
53
75
|
|
54
76
|
# @private
|
@@ -82,7 +104,9 @@ module Tekeya
|
|
82
104
|
def group_activities
|
83
105
|
if self.group_with_recent
|
84
106
|
self.created_at = current_time_from_proper_timezone
|
85
|
-
rel = self.class.where(created_at: self.created_at, activity_type: self.activity_type,
|
107
|
+
rel = self.class.where( created_at: self.created_at, activity_type: self.activity_type,
|
108
|
+
entity_id: self.entity_id, entity_type: entity_type,
|
109
|
+
author_id: self.author_id, author_type: self.author_type)
|
86
110
|
if rel.count > 0
|
87
111
|
activity = rel.first
|
88
112
|
activity.attachments << self.attachments
|
@@ -122,4 +146,4 @@ module Tekeya
|
|
122
146
|
end
|
123
147
|
end
|
124
148
|
end
|
125
|
-
end
|
149
|
+
end
|
@@ -21,12 +21,12 @@ module Tekeya
|
|
21
21
|
key_components = key.split(':')
|
22
22
|
|
23
23
|
act_id = key_components[1]
|
24
|
-
act_type = key_components[
|
25
|
-
act_time = Time.at(key_components[
|
24
|
+
act_type = key_components[6].to_sym
|
25
|
+
act_time = Time.at(key_components[7].to_i)
|
26
26
|
|
27
27
|
if act_actor.nil?
|
28
|
-
actor_class = key_components[
|
29
|
-
act_actor = actor_class.where(:"#{actor_class.entity_primary_key}" => key_components[
|
28
|
+
actor_class = key_components[4].safe_constantize
|
29
|
+
act_actor = actor_class.where(:"#{actor_class.entity_primary_key}" => key_components[5]).first
|
30
30
|
end
|
31
31
|
|
32
32
|
act_attachments = ::Tekeya.redis.smembers(key).map{|act|
|
@@ -47,7 +47,7 @@ module Tekeya
|
|
47
47
|
act_id = activity.id.to_s
|
48
48
|
act_type = activity.activity_type.to_sym
|
49
49
|
act_time = activity.created_at
|
50
|
-
act_actor ||= activity.entity
|
50
|
+
act_actor ||= activity.author || activity.entity
|
51
51
|
act_attachments = activity.attachments.map(&:attachable)
|
52
52
|
|
53
53
|
return self.new(act_id, act_type, act_attachments, act_actor, act_time)
|
@@ -12,6 +12,7 @@ module Tekeya
|
|
12
12
|
def self.perform(untracked_feed_key, untracker_feed_key)
|
13
13
|
# get the keys to the activities so we can decrement the counters later
|
14
14
|
activity_keys = ::Tekeya.redis.zrange(untracked_feed_key, 0, -1)
|
15
|
+
return if activity_keys.empty?
|
15
16
|
|
16
17
|
::Tekeya.redis.multi do
|
17
18
|
# delete the latest activities of the untracked entity from the tracker feed
|
@@ -9,6 +9,7 @@ module Tekeya
|
|
9
9
|
belongs_to :notification_attache, polymorphic: true, autosave: true
|
10
10
|
|
11
11
|
include ActiveModel::Serializers::JSON
|
12
|
+
attr_accessible :attache, :attachable, :notification_attache
|
12
13
|
end
|
13
14
|
|
14
15
|
module ClassMethods
|
@@ -16,4 +17,4 @@ module Tekeya
|
|
16
17
|
|
17
18
|
end
|
18
19
|
end
|
19
|
-
end
|
20
|
+
end
|
@@ -15,6 +15,7 @@ module Tekeya
|
|
15
15
|
validates_presence_of :actors
|
16
16
|
|
17
17
|
attr_writer :group_with_recent
|
18
|
+
attr_accessible :entity, :subject, :actors, :notification_type, :read, :group_with_recent
|
18
19
|
end
|
19
20
|
|
20
21
|
module ClassMethods
|
@@ -90,4 +91,4 @@ module Tekeya
|
|
90
91
|
end
|
91
92
|
end
|
92
93
|
end
|
93
|
-
end
|
94
|
+
end
|
data/lib/tekeya/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -35,7 +35,7 @@ RSpec.configure do |config|
|
|
35
35
|
DatabaseCleaner.clean
|
36
36
|
end
|
37
37
|
|
38
|
-
config.
|
38
|
+
config.before(:each) do
|
39
39
|
Tekeya.relations.truncate
|
40
40
|
Tekeya.redis.flushall
|
41
41
|
end
|
@@ -63,7 +63,7 @@ RSpec.configure do |config|
|
|
63
63
|
"loglevel" => "debug",
|
64
64
|
"logfile" => "stdout",
|
65
65
|
"databases" => 16
|
66
|
-
}.map { |k, v| "#{k} #{v}" }.join(
|
66
|
+
}.map { |k, v| "#{k} #{v}" }.join("\n")
|
67
67
|
`echo '#{redis_options}' | redis-server -`
|
68
68
|
end
|
69
69
|
|
@@ -75,4 +75,4 @@ RSpec.configure do |config|
|
|
75
75
|
|
76
76
|
FileUtils.rm_r "#{File.dirname(__FILE__)}/rails_app/db/test.sqlite3" rescue nil
|
77
77
|
end
|
78
|
-
end
|
78
|
+
end
|
@@ -104,7 +104,10 @@ describe "Tekeya" do
|
|
104
104
|
@act1.destroy
|
105
105
|
@act3.destroy
|
106
106
|
@act4.destroy
|
107
|
-
|
107
|
+
|
108
|
+
Timecop.travel(Time.at(20.minutes)) do
|
109
|
+
@act5.destroy
|
110
|
+
end
|
108
111
|
end
|
109
112
|
|
110
113
|
it "should remove the activity from the cache when its deleted from the db" do
|
@@ -167,4 +170,4 @@ describe "Tekeya" do
|
|
167
170
|
end
|
168
171
|
end
|
169
172
|
end
|
170
|
-
end
|
173
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tekeya
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-01-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: redis
|
17
|
-
requirement: &
|
17
|
+
requirement: &70269641288980 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 3.0.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70269641288980
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rebat
|
28
|
-
requirement: &
|
28
|
+
requirement: &70269641287740 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 0.1.4
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70269641287740
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: resque
|
39
|
-
requirement: &
|
39
|
+
requirement: &70269641285760 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.23.0
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70269641285760
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: railties
|
50
|
-
requirement: &
|
50
|
+
requirement: &70269641284580 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '3.1'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70269641284580
|
59
59
|
description: a social engine for Rails applications based on Redis and RebatDB
|
60
60
|
email:
|
61
61
|
- omar.mekky@mashsolvents.com
|