팔로워 관계를 구축하기 위해 테이블을 디자인하려고합니다.appengine에서 팔로워 스트림을 모델링하는 방법은 무엇입니까?
사용자, 해시 태그 및 기타 텍스트가있는 140char 레코드 스트림이 있다고 가정 해보십시오.
사용자가 다른 사용자를 추적하고 해시 태그를 추적 할 수도 있습니다.
아래에서 설계 한 방법을 간략히 설명하지만 디자인에는 두 가지 제한 사항이 있습니다. 다른 사람들이 같은 목표를 달성하는 더 똑똑한 방법을 갖고 있는지 궁금합니다. 이와
이슈는
- 추종자의 목록은 새로운 추종자가 추가되거나 하나가 제거한 경우 각 레코드
- 위해 안으로 복사, '모든'을 레코드를 업데이트해야이다. 이 작업을 수행하는 똑똑한 방법은
코드
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)
있습니까?
복제 됨 http://stackoverflow.com/questions/2668470/good-way-of-implementing-a-twitter-like-follower-system –