2

first of all a little of what I am trying to achieve. I have built a django wrapper on top of stream-framework library. There are 2 feed-classes - FlatFeed(RedisFeed) and AggregatedFeed(RedisAggregatedFeed). Obviously, these are using Redis to store the feed data. I have also implemented my own aggregator class.

Error: The generated aggregated feed doesn't contain all activities while the flat feed has all the activities. The use-case is - there are 3 users A, B and C. B and C performs some activities, then user A follows B and C. User B and C keep on doing more activities. Flat feed of A contains all the activities of B and C, but aggregated feed of A has some lost activities.

For example,

B likes products 1, 2, 3, 4
C likes products 5, 6, 7, 8, 9, 10
A follows B
A follows C

flat_feed(A) has all activities, but aggregated_feed(A) only has likes for 1, 5 and 8. I repeated this use-case several times and each time only these 3 activities are coming.

I have tested my aggregator class implementation on django shell. The output of aggregate and merge function contains all the activities.

Please help !!

Please note that flat feed has correct entries, the missing entries are only in aggregated feeds.

Mikhail_Sam
  • 10,602
  • 11
  • 66
  • 102
Anunaya Srivastava
  • 175
  • 1
  • 2
  • 12

2 Answers2

1

I have found the solution. I rewrote the serialization_id method of AggregatedActivity as -

def serialization_id(self):
    milliseconds = str(int(datetime_to_epoch(self.updated_at)* 1000))
    return milliseconds
Anunaya Srivastava
  • 175
  • 1
  • 2
  • 12
0

If you look at the AggregatedActivity class of the framework, you will notice that the serialization_id aka the unique identifier of the activity is calculated based on the number of seconds from epoch. This means that the activities that are performed within one second will be overwritten.

You can solve this by redefining the serialization_id.
serialization_id = number of milliseconds from epoch.
This should work fine.

Ashutosh Tiwari
  • 984
  • 6
  • 16