tekeya 0.0.4 → 0.0.5

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/lib/tekeya/entity.rb CHANGED
@@ -336,7 +336,7 @@ module Tekeya
336
336
  # Check if the cache is not empty
337
337
  if recent_activities_count > 0
338
338
  # Retrieve the aggregate keys from redis
339
- acts_keys = ::Tekeya.redis.zrange(fkey, 0, -1)
339
+ acts_keys = ::Tekeya.redis.zrevrange(fkey, 0, -1)
340
340
  # Retrieve the aggregates
341
341
  acts_keys.each do |act_key|
342
342
  acts << ::Tekeya::Feed::Activity::Item.from_redis(act_key, self)
@@ -61,7 +61,16 @@ module Tekeya
61
61
  def write_activity_in_redis
62
62
  akey = activity_key
63
63
  tscore = score
64
- ::Resque.enqueue(::Tekeya::Feed::Activity::Resque::ActivityFanout, self.entity_id, self.entity_type, akey, tscore, self.attachments.map{ |att| att.to_json(root: false, only: [:attachable_id, :attachable_type]) })
64
+ attachments_json = self.attachments.map{ |att| att.to_json(root: false, only: [:attachable_id, :attachable_type]) }
65
+
66
+ # write the activity to the aggregate set and the owner's feed
67
+ ::Tekeya.redis.multi do
68
+ write_aggregate
69
+ ::Tekeya::Feed::Activity::Resque::ActivityFanout.write_to_feed(self.entity.profile_feed_key, tscore, akey)
70
+ ::Tekeya::Feed::Activity::Resque::ActivityFanout.write_to_feed(self.entity.feed_key, tscore, akey)
71
+ end
72
+
73
+ ::Resque.enqueue(::Tekeya::Feed::Activity::Resque::ActivityFanout, self.entity_id, self.entity_type, akey, tscore)
65
74
  end
66
75
 
67
76
  # @private
@@ -96,6 +105,17 @@ module Tekeya
96
105
  # floors the timestamp to the nearest 15 minute
97
106
  return Time.at((stamp.to_f / 15.minutes).floor * 15.minutes)
98
107
  end
108
+
109
+ # Writes the activity and its' attachments to the aggregate set
110
+ #
111
+ # @param [String] activity_key the key of the activity to be added
112
+ # @param [Array] attachments an array of attachments associated with the activity
113
+ def write_aggregate
114
+ # save the aggregate set
115
+ self.attachments.map{ |att| att.to_json(root: false, only: [:attachable_id, :attachable_type]) }.each do |attachment|
116
+ ::Tekeya.redis.sadd(activity_key, attachment)
117
+ end
118
+ end
99
119
  end
100
120
  end
101
121
  end
@@ -9,7 +9,6 @@ module Tekeya
9
9
  end
10
10
 
11
11
  module ClassMethods
12
- private
13
12
  # Writes the activity reference to the feed with the supplied key
14
13
  #
15
14
  # @param [String] feed_key the key of the feed where the activity will be referenced
@@ -23,6 +22,7 @@ module Tekeya
23
22
  ::Tekeya.redis.incr(activity_counter_key)
24
23
  end
25
24
 
25
+ private
26
26
  # Trims the feed according to the MAXTIMESTAMP set and returns the removed keys (for garbage collection)
27
27
  #
28
28
  # @param [String] feed_key a string containing the key of the feed to be trimed
@@ -9,22 +9,15 @@ module Tekeya
9
9
  @queue = :activity_queue
10
10
 
11
11
  # @private
12
- def self.perform(entity_id, entity_type, activity_key, score, attachments)
12
+ def self.perform(entity_id, entity_type, activity_key, score)
13
13
  # get the entity class
14
14
  entity_type = entity_type.safe_constantize
15
15
  entity = entity_type.where(entity_type.entity_primary_key.to_sym => entity_id).first
16
16
  # we only need the feed keys of the trackers
17
17
  entity_trackers_feeds = entity.trackers.map(&:feed_key)
18
- entity_trackers_feeds << entity.feed_key
19
18
  # keep track of the keys we delete in the trim operation for garbage collection
20
19
  removed_keys = []
21
20
 
22
- # write the activity to the aggregate set and the owner's feed
23
- ::Tekeya.redis.multi do
24
- write_aggregate(activity_key, attachments)
25
- write_to_feed(entity.profile_feed_key, score, activity_key)
26
- end
27
-
28
21
  # trim the profile feed
29
22
  removed_keys += trim_feed(entity.profile_feed_key)
30
23
 
@@ -42,19 +35,6 @@ module Tekeya
42
35
  # cleanup the garbage
43
36
  collect_garbage removed_keys
44
37
  end
45
-
46
- private
47
-
48
- # Writes the activity and its' attachments to the aggregate set
49
- #
50
- # @param [String] activity_key the key of the activity to be added
51
- # @param [Array] attachments an array of attachments associated with the activity
52
- def self.write_aggregate(activity_key, attachments)
53
- # save the aggregate set
54
- attachments.each do |attachment|
55
- ::Tekeya.redis.sadd(activity_key, attachment)
56
- end
57
- end
58
38
  end
59
39
  end
60
40
  end
@@ -1,3 +1,3 @@
1
1
  module Tekeya
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  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
4
+ version: 0.0.5
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: 2012-11-07 00:00:00.000000000 Z
13
+ date: 2012-11-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: redis
17
- requirement: &70286481928400 !ruby/object:Gem::Requirement
17
+ requirement: &70167657241820 !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: *70286481928400
25
+ version_requirements: *70167657241820
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rebat
28
- requirement: &70286481921620 !ruby/object:Gem::Requirement
28
+ requirement: &70167657235060 !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: *70286481921620
36
+ version_requirements: *70167657235060
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: resque
39
- requirement: &70286481918560 !ruby/object:Gem::Requirement
39
+ requirement: &70167657232000 !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: *70286481918560
47
+ version_requirements: *70167657232000
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: railties
50
- requirement: &70286481911860 !ruby/object:Gem::Requirement
50
+ requirement: &70167657225340 !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: *70286481911860
58
+ version_requirements: *70167657225340
59
59
  description: a social engine for Rails applications based on Redis and RebatDB
60
60
  email:
61
61
  - omar.mekky@mashsolvents.com