Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用户互相关注与屏蔽系统设计 #5

Open
codetalks-new opened this issue Feb 20, 2019 · 0 comments
Open

用户互相关注与屏蔽系统设计 #5

codetalks-new opened this issue Feb 20, 2019 · 0 comments
Labels
用户关注 用户互相关注相关设计及演进

Comments

@codetalks-new
Copy link
Owner

codetalks-new commented Feb 20, 2019

关注和屏蔽操作不可少。本 issue 主要关注于用户之间的互相关注与 blocked.
这是一个多对多的操作。

一个用户对另一个用户的关联,主要就是“关注”或“屏蔽”。
使用一个枚举的表示这两种关系。

class UserRelationState(IntEnum):
  FOLLOWING = 1  # 关注
  BLOCKING = 4  # 屏蔽

  @property
  def label(self):
    return _user_relation_state_to_text[self]


_user_relation_state_to_text = {
  UserRelationState.FOLLOWING: "关注",
  UserRelationState.BLOCKING: "屏蔽"
}

在这个多对多的关系中,关注和屏蔽其实是互斥的,所以可以记录在同一条记录上。

class UserRelation(BaseModel):
  from_user = models.ForeignKey(WepostUser,on_delete=models.CASCADE,verbose_name="用户")
  to_user = models.ForeignKey(WepostUser,on_delete=models.CASCADE, verbose_name="目标用户")
  state = models.PositiveSmallIntegerField("状态", choices=UserRelationState.choices())

  class Meta:
    unique_together = ("from_user", "to_user")
    verbose_name = "关注与屏蔽"
    verbose_name_plural = verbose_name

由于同一个用户对另一个用户只维护一个关注,所以这里使用复合的索引 ,通过限定 from_user,to_user 的维护性,也是隐式的告诉数据库这里需要索引。

@codetalks-new codetalks-new added the 用户关注 用户互相关注相关设计及演进 label Feb 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
用户关注 用户互相关注相关设计及演进
Projects
None yet
Development

No branches or pull requests

1 participant