English 中文(简体)
G. 通用公平市价
原标题:Modeling Votes on GAE

我试图确定最有效的方式,建立一个关于GAE数据库的有价证券实体。 我要向用户表明,对这个实体投票的控制,或者说,他们已经投票支持该实体;即,我要求“用户对这个实体投了票吗?” 让我们说,我们有一个问答实体,用户可以公开。 这里我想的是:

  1. Query for my Question entities. These questions already have a precalculated ranking on which I will sort.
  2. Use a relation index entity that is a child of the Question entity. Query for all Questions using the same filters as #1 where my user is a member of this relation index entity.
  3. Merge the results of #2 into #1 by setting a hasVoted property to true for each found set member.

这是我可以想做的最干净的方法,但还需要两个问题。 我没有为每个用户创建重复的问答实体,因为这会造成太多的数据重复。 这种办法是否是有效处理在选民和问题之间的两点关系之间或我是否认为关系过密切的问题的一个好办法?

问题回答

没有任何关系指数,只是每个使用者都有一个儿童实体来就这一问题进行表决。 将儿童实体的名称定为用户身份。 然后,为了确定用户与IDx就一个问题进行表决,仅指钥匙(问题:x/Vote:y)。 你们也可以这样做,为多个问题或用户寻找多个实体。

为避免第二次询问,您可以储存用户在一个单一实体表决的问题的all。 该实体可以是用户模式的一部分,也可以是与用户实体的单对一的关系。

然后,你可以按需要把这一信息装上(并把它储存到顶点,以避免数据储存负荷),这样,如果用户已经对一个问题进行表决(在大部分时间没有进行第二次查询),你就可以迅速检查。

如果用户可以就数量庞大的问题进行表决,那么你可能必须扩大这一想法。 页: 1 您可如何采用简单办法(而不是在功能上完成):

class UserVotes(db.Model):
    # key = key_name or ID of the corresponding user entity

    # if all of your question entities have IDs, then voted_on can be a list of 
    # integers; otherwise it can be a list of strings (key_name values)
    voted_on = db.ListProperty(int, indexed=False)  

# in your request handler ...
questions = ...
voted_on = memcache.get( voted-on:%s  % user_id)
if voted_on is None:
    voted_on = UserVotes.get_by_id(user_id)  # should do get_or_insert() instead
    memcache.set(...)
for q in questions:
    q.has_voted = q.key().id() in voted_on




相关问题
How to make logging.debug work on Appengine?

I m having a tough time getting the logging on Appengine working. the statement import logging is flagged as an unrecognized import in my PyDev Appengine project. I suspected that this was just an ...

gqlQuery returns object, want list of keys

Is there a way to convert the GqlQuery object to an array of keys, or is there a way to force the query to return an array of keys? For example: items = db.GqlQuery("SELECT __key__ FROM Items") ...

Integrating Google AppEngine with a Thick Client

I want to make a multi-user client-server solution with Java Swing thick client as a front-end and Google AppEngine (Java one) as a back-end. The problem is that GAE provides only web-based forms for ...

sorl.thumbnail : thumbnail is not a valid tag library?

I am trying to install sorl.thumbnail but am getting the following error message: thumbnail is not a valid tag library: Could not load template library from django.templatetags.thumbnail, No module ...

热门标签