App Engine Messaging System with Message Status - Design Pattern

泪湿孤枕 提交于 2019-12-21 22:32:49

问题


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:


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.



来源:https://stackoverflow.com/questions/6349529/app-engine-messaging-system-with-message-status-design-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!