2010-05-24 3 views
3

팔로워 관계를 구축하기 위해 테이블을 디자인하려고합니다.appengine에서 팔로워 스트림을 모델링하는 방법은 무엇입니까?

사용자, 해시 태그 및 기타 텍스트가있는 140char 레코드 스트림이 있다고 가정 해보십시오.

사용자가 다른 사용자를 추적하고 해시 태그를 추적 할 수도 있습니다.

아래에서 설계 한 방법을 간략히 설명하지만 디자인에는 두 가지 제한 사항이 있습니다. 다른 사람들이 같은 목표를 달성하는 더 똑똑한 방법을 갖고 있는지 궁금합니다. 이와

이슈는

  1. 추종자의 목록은 새로운 추종자가 추가되거나 하나가 제거한 경우 각 레코드
  2. 위해 안으로 복사, '모든'을 레코드를 업데이트해야

    이다. 이 작업을 수행하는 똑똑한 방법은

코드

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) 

있습니까?

+0

복제 됨 http://stackoverflow.com/questions/2668470/good-way-of-implementing-a-twitter-like-follower-system –

답변

1

예이 팬 아웃 문제 : 당신은 여기에 이야기의 비디오를 찾을 수 있습니다. 그들은 버그가 아니라 기능이 아니라고로

그러나, 나는 즉

  • 추종자의 목록은 각 레코드

이를 위해에 복사이 특정 한계를 올렸다. 사실 appengine 비늘에 팬 아웃이 적용됩니다.

  • 새 팔로어가 추가되거나 제거되면 'all'레코드를 업데이트해야합니다.

아무 것도하지 않으므로 향후 레코드를 따르지 않습니다. 다른 말로하면 사람들의 흐름을 따르는 것이 아니라 주어진 시간에 사람들의 흐름을 따르는 것입니다.따라서 2 일째에 팔로우 해제하면 팔로워 스트림에 사용자의 기록이 표시되지만 1 일 이후에는 표시되지 않지만 2 일 이후는 표시되지 않습니다. [참고 : 이것은 트위터가하는 방식과 다릅니다]

0

당신은 reference 속성을 사용하고 당신은 내가 구글 앱 엔진에서이 작업을 수행하는 방법을 잘 모르겠어요

-1

에 참조 그것의 추종자들과 공통의 테이블을 가지고 있지만 하나의 데이터베이스 스키마 I 수 것이라고 생각 : 당신은 아마 하나에 두 개의 비트 열을 응축 수 있지만, 이것은 당신이 사용자가 미래에 수행 할 수있는 다른 일을 추가 할 수 있도록 할

 
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) 

.

+2

appengine 데이터베이스 구현 매우 독특하고 특정 응답을 찾고 있습니다. – molicule

5

해결하려는 문제를 팬 아웃 문제라고합니다.

Google App Engine 팀의 Brett Slatkin이 효율적이고 확장 가능한 솔루션을 사용하여 App Engine에서 팬 아웃 문제를 해결했습니다. 다른 사람들이 지적하고 브렛 슬래트 킨의 이야기는 관심이있는 사람들에 의해 바라 보았다되어야로

http://code.google.com/events/io/2009/sessions/BuildingScalableComplexApps.html

관련 문제