Well I figured out a sort of fix (similar to urs but doesn't require
pinging from external box):

I basically added a list property to MainListOfArticles that contains
all the user objects that commented on that specific article [I'll
call it CommentsOnArticles]. So every time someone comments I add a
comment to the CommentsOnArticles (once for each user!), and also
update the MainListOfArticles entity. I also added an entity called
lastCommentedOnDate which is updated every time a new user comments.

So when a user logs in I simply use s/t like the following code
(snipped out) to fetch all his articles that were commented on:

q=db.Query(MainListOfArticles)
q.filter('usersThatCommented =',currentUser)
q.order('-lastCommentedOnDate') //ascending or descending depending on
ur preference
results = q.fetch(5)

You will also need a special index for this query (that usually is
added automatically through the SDK)

The only problem is that if ___too___ (it would have to be like 1000s,
I think) many different users comment on one single article you could
go over the 1 MB per entity limit...



On Nov 12, 7:18 pm, Alexander Kojevnikov <[EMAIL PROTECTED]>
wrote:
> Great question!
>
> I have a somewhat similar model in my app (it's not articles but the
> query is similar), here's how I do it:
>
> I de-normalise the data specifically for this query, that is I have a
> kind:
>
> UserComment:
>     user = db.UserProperty()
>     last_commented = db.DateTimeProperty()
>     # de-normalised data from the article model (key, title, slug,
> etc).
>
> When the user creates a comment, I add a UserComment if it's the first
> comment for the user in this article.
>
> I also add an entity to the job queue model for background processing.
> The background worker (triggered by pinging from an external box)
> updates UserComment.last_commented for all users that also commented
> the article.
>
> It's far from perfect, there's a (slight) delay in update, but
> otherwise it works. I'm very interested in how others would implement
> this.
>
> Alex
> --www.muspy.com
>
> On Nov 13, 9:50 am, MajorProgamming <[EMAIL PROTECTED]> wrote:
>
>
>
> > I was wondering how to approach the following:
>
> > Suppose I have three DB Models that look something like this:
>
> > MainListOfArticles(db.Model):
> > articleText=db.Text
> > [...]
>
> > CommentsOnArticles(db.Model):
> > commentText=db.Text
> > articleRef=db.ReferenceProperty(MainListOfArticles)
> > userThatWrote=db.UserProperty
> > [...]
>
> > Users(db.Model):
> > userObject=db.UserProperty
> > [...]
>
> > Now suppose I would like to retreive all articles that the user
> > commented on, based on the recency of the latest comment on that
> > article. I.e: when a user logs in he gets a decending list of all
> > articles *that he commented on* sorted by how recently they were
> > commented on (by others).
>
> > To put it in other words: To get all articles based on the recency of
> > their comments would be easy: simply retrieve the comments sorted by
> > order descending. However, I would like a way to specifically retreive
> > those that the user commented on.
>
> > Another point: I want the solution to scale. Keep in mind that there
> > could be an infinite number of articles and users. So storing them in
> > an individual entity would not work. There is a 1MB limit per entity
> > (that probably squashes many possible solutions).
>
> > Thanks for your help,
>
> > And if I didn't explain everything correctly, please ask me to clarify
> > a point....- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to