0

I'm currently designing an application similar to twitter/jaiku/reddit in structure. Basically there are small posts with upvotes and downvotes, and they are sorted by score and time like reddit.

I've gotten all of this working, but now our requirements have changed a bit, and we need the user to be able to mark a post as 'read'. This would make the post no longer show up in that user's feed. I can model this with a Read entity for each tuple of (User, Post), but this would require a lot of work to find posts which 'do not' exist in that table. Alternatively I can invert that relation so that I have one entity for each unread post, and it becomes much easier to find which posts 'do' exist in the table... But then I'd need to create an entry in this table for every single user everytime a post is made. This would not scale well.

My question is this: How would I model this sort of negative information in appengine's datastore? I'm using the go runtime if that matters, but answers for any runtime are fine.

Logiraptor
  • 1,496
  • 10
  • 14

1 Answers1

0

This would be a many-to-many relationship. This article describes how to model different kinds of relationships, including many-to-many. The only issue is that I'm not sure weather you should store a list of read posts on the user, or a list of users who have read it, on the post, as poth lists might get large in different situations. If posts are relatively private, and not seen by many people, you could store a list of user keys on the post model. But, if one post could be seen by thousands of people, it might be better to store a list of posts on the users, as there wil probably not be many users with thousands of read posts. Another option might be to discard old posts, or just discard their read state.

bigblind
  • 12,539
  • 14
  • 68
  • 123
  • Oh ok. I read somewhere that they are limited to 5000 elements because of the indexed property limit. How would i use that in a query? I think the IN operator is limited to 30 elements at a time. – Logiraptor Feb 27 '14 at 00:48
  • I'm actually not sure my answer is valid anymore, after reading Guido Vanrossum's answer to this question: http://stackoverflow.com/questions/15377119/gae-ndb-design-performance-and-use-of-repeated-properties, even though he's talking about ndb, the python datastore api, I think this is about the way repeated properties are handled under the hood. – bigblind Feb 27 '14 at 01:14
  • Yeah it seems like they aren't intended for large lists like that. The problem is still the fact that the information I'm trying to capture is negative. I don't see any way to find entities which are *not* in a list regardless of the representation chosen. – Logiraptor Feb 27 '14 at 01:44
  • It would probably not be too much overhead to get all the posts out of the datastore, even the read ones, and then check for their read status before putting them in the template, or passing them to the client in an other way. – bigblind Feb 27 '14 at 02:08