English 中文(简体)
如何模仿 app流?
原标题:how to model a follower stream in appengine?

我试图设计表格,以建立跟踪关系。

Saye 我有140个有用户、信使和其他文本的记录。

用户跟着其他用户,也可以跟踪冲锋。

我将概述我如何制定以下目标,但我的设计有两点限制。 我很想知道,其他人是否拥有实现同样目标的更加划时代的方法。

这里的问题是:

  1. The list of followers is copied in for each record
  2. If a new follower is added or one removed, all the records have to be updated.

法典

class HashtagFollowers(db.Model):
    """
    This table contains the followers for each hashtag
    """
    hashtag = db.StringProperty()
    followers = db.StringListProperty()

class UserFollowers(db.Model):
    """
    This table contains the followers for each user
    """
    username = db.StringProperty()
    followers = db.StringListProperty()

class stream(db.Model):
    """
    This table contains the data stream
    """
    username = db.StringProperty()
    hashtag = db.StringProperty()
    text = db.TextProperty()

    def save(self):
        """
        On each save all the followers for each hashtag and user
        are added into a another table with this record as the parent
        """
        super(stream, self).save()
        hfs = HashtagFollowers.all().filter("hashtag =", self.hashtag).fetch(10)
        for hf in hfs:
            sh = streamHashtags(parent=self, followers=hf.followers)
            sh.save()
        ufs = UserFollowers.all().filter("username =", self.username).fetch(10)
        for uf in ufs:
            uh = streamUsers(parent=self, followers=uf.followers)
            uh.save()



class streamHashtags(db.Model):
    """
    The stream record is the parent of this record
    """
    followers = db.StringListProperty() 

class streamUsers(db.Model):
    """
    The stream record is the parent of this record
    """
    followers = db.StringListProperty()

Now, to get the stream of followed hastags 

    indexes = db.GqlQuery("""SELECT __key__ from streamHashtags where followers =  myusername """)
    keys = [k,parent() for k in indexes[offset:numresults]]
    return db.get(keys)

是否有更明智的办法这样做?

最佳回答

是的,正如其他人指出的那样,这是狂热的问题,而有关人士应当研究布尔特·斯拉提金的话。

然而,我提出了两项具体限制,即:

  • The list of followers is copied in for each record

他们说,这不是一个 b,而是一个特有。 事实上,正是以这种方式,狂热在 app度上。

  • If a new follower is added or one removed, all the records have to be updated.

无论是哪怕是其他资源,都跟不上今后的记录。 换言之,一个人不仅仅跟随人流,而是在一定时间跟随人流。 因此,如果你在第2天没有打字,你的追随者将仍然从一天起的用户那里,而不是两天和以后的记录。 [说明:这不同于前导体是如何做到的]。

问题回答

你想要解决的问题被称为狂热问题。

谷歌搜索引擎小组的Brett Slatkin讲了有效/可衡量的办法,解决了上诉发动机的狂热问题。 你们可以找到这里的谈话录像:

I m不肯定谷歌应用公司如何做到这一点,但一个数据库图示一认为:

Tables:
    User    -- a table of users with their attributes
    HashTag -- a table of HashTags with their attributes
    Follows -- a table that defines who follows whom

Columns in the Follows table:
    followed int,         -- the id of the followed entity (could be 
                             User or Hashtag)
    followed_is_user bit, -- whether the followed item is a User
    followed_is_tag bit,  -- whether the followed item is a HashTag
    follower int          -- the id of the follower (this can only be 
                             a User so you may want to make this a foreign 
                             key on the User table)

也许你会把两列轨道一栏混为一谈,但这将使你能够添加用户今后可以效仿的其他内容。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签