Note that there are some explanatory texts on larger screens.

plurals
  1. POApp Engine Messaging System with Message Status - Design Pattern
    text
    copied!<p>I'm building a Threaded Messaging System that will be hosted on Google AppEngine</p> <p>I've modeled it after the technique described by Brett Slatkin in <a href="http://www.google.com/events/io/2009/sessions/BuildingScalableComplexApps.html" rel="nofollow">Building Scalable, Complex Apps on App Engine</a></p> <pre><code>class Message(db.Model): sender = db.StringProperty() body = db.TextProperty() class MessageIndex(db.Model): receivers = db.StringListProperty() </code></pre> <p>The issue I'm having to determining the most efficient way to track the message state for a User. For example is a message <code>read</code>, <code>archived</code>, <code>deleted</code> for a particular user.</p> <p>Here are the solution I have come up with so far.</p> <p>I'm using <a href="http://code.google.com/p/appengine-ndb-experiment/" rel="nofollow">Datastore+</a>'s StructuredProperty to add a state to the message <code>MessageIndex</code></p> <pre><code>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) </code></pre> <p>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.</p> <p><a href="https://gist.github.com/1025736" rel="nofollow">Full Source Code</a></p> <p>What would be the most efficient way to accomplish this? Would adding an additional entity group be a better solution?</p> <pre><code>class MessageState(model.Model): user_key = model.KeyProperty() message_key = model.KeyPropery() message_state = model.IntegerProperty(default=0) # 0-unread, 1-read, 2-archived </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload