App Engine Messaging System with Message Status -

2019-04-13 05:18发布

I'm building a Threaded Messaging System that will be hosted on Google AppEngine

I've modeled it after the technique described by Brett Slatkin in Building Scalable, Complex Apps on App Engine

class Message(db.Model):
  sender = db.StringProperty()
  body = db.TextProperty()

class MessageIndex(db.Model):
  receivers = db.StringListProperty()

The issue I'm having to determining the most efficient way to track the message state for a User. For example is a message read, archived, deleted for a particular user.

Here are the solution I have come up with so far.

I'm using Datastore+'s StructuredProperty to add a state to the message MessageIndex

class Message(model.Model):
  sender = model.StringProperty()
  body = model.TextProperty()

class _DisplayState(model.Model):
  user_key = model.KeyProperty()
  state = model.IntegerProperty(default=0) # 0-unread, 1-read, 2-archived

class MessageIndex(model.Model):
  receivers = model.StructuredProperty(_DisplayState, repeated=True)

This solution, while simple, negates the benefit of the MessageIndex. Additionally since the the MessageIndex is in the same entity group as the message datastore writes will be limited.

Full Source Code

What would be the most efficient way to accomplish this? Would adding an additional entity group be a better solution?

class MessageState(model.Model):
  user_key = model.KeyProperty()
  message_key = model.KeyPropery()
  message_state = model.IntegerProperty(default=0) # 0-unread, 1-read, 2-archived

1条回答
Viruses.
2楼-- · 2019-04-13 05:54

For the easiest querying - split your 'receivers' list into four different lists - 'unread', 'read', 'archived', 'deleted' and shuffle the receiver record between the lists as appropriate.

查看更多
登录 后发表回答