具有消息状态的App Engine消息系统 - 设计模式 [英] App Engine Messaging System with Message Status - Design Pattern

查看:127
本文介绍了具有消息状态的App Engine消息系统 - 设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个将在Google AppEngine上托管的Threaded Messaging系统



我已经使用Brett Slatkin描述的技术对在App Engine上构建可扩展的复杂应用程序

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

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

我不得不确定跟踪用户消息状态的最有效方法。
例如,一条消息读取存档已删除

以下是我到目前为止所提出的解决方案。



我使用 Datastore + 的StructuredProperty将状态添加到消息 MessageIndex

  class Message(model.Model):
sender = model.StringProperty()
body = model.TextProperty()
$ b $ class _DisplayState(model.Model):
user_key = model.KeyProperty()
state = model.IntegerProperty(default = 0)#0-未读,1-read,2-archived
$ b $ class MessageIndex(model.Model):
receivers = model.StructuredProperty(_DisplayState,repeated =真)

这个解决方案虽然简单,却否定了MessageIndex的好处。此外,由于MessageIndex与消息数据存储的写入限制在同一个实体组中。



完整的源代码



完成此操作最有效的方法是什么?添加额外的实体组是一个更好的解决方案吗?

  class MessageState(model.Model):
user_key = model .KeyProperty()
message_key = model.KeyPropery()
message_state = model.IntegerProperty(default = 0)#0 - 未读,1读,2 - 归档

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

解决方案

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.

这篇关于具有消息状态的App Engine消息系统 - 设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆