Documentation ¶
Index ¶
- Constants
- type Dao
- type LinkStatus
- type Relation
- type RelationDao
- func (d *RelationDao) CountUidFans(ctx context.Context, uid uint64) (uint64, error)
- func (d *RelationDao) CountUidFollowings(ctx context.Context, uid uint64) (uint64, error)
- func (d *RelationDao) FindAlphaGotLinked(ctx context.Context, alpha uint64) ([]uint64, error)
- func (d *RelationDao) FindAlphaLinkTo(ctx context.Context, alpha uint64) ([]uint64, error)
- func (d *RelationDao) FindBetaGotLinked(ctx context.Context, beta uint64) ([]uint64, error)
- func (d *RelationDao) FindBetaLinkTo(ctx context.Context, beta uint64) ([]uint64, error)
- func (d *RelationDao) FindByAlphaBeta(ctx context.Context, a, b uint64, forUpdate bool) (*Relation, error)
- func (d *RelationDao) FindByAlphaBetaAndLink(ctx context.Context, a, b uint64, link LinkStatus, forUpdate bool) (*Relation, error)
- func (d *RelationDao) FindUidGotLinked(ctx context.Context, uid, offset uint64, limit int) (uids []uint64, next uint64, more bool, err error)
- func (d *RelationDao) FindUidLinkTo(ctx context.Context, uid, offset uint64, limit int) (uids []uint64, next uint64, more bool, err error)
- func (d *RelationDao) Insert(ctx context.Context, r *Relation) error
- func (d *RelationDao) UpdateLink(ctx context.Context, r *Relation) error
- type RelationSetting
- type RelationSettingDao
Constants ¶
View Source
const ( ShowFollowings = 0 // 展示关注列表 NotShowFollowings = 1 // 不展示关注列表 NotShowFans = 0 // 不展示粉丝列表 ShowFans = 1 // 展示粉丝列表 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dao ¶
type Dao struct { RelationDao *RelationDao // contains filtered or unexported fields }
type LinkStatus ¶
type LinkStatus int8
const ( LinkVacant LinkStatus = 0 // 没有关系 LinkForward LinkStatus = 2 // A单向关注B LinkBackward LinkStatus = -2 // B单向关注A LinkMutual LinkStatus = -4 // AB互相关注 )
Link的状态转移
初次关注 LinkVacant -> LinkForward/LinkBackward 单向关注,随后取消关注 LinkForward/LinkBackward -> LinkVacant 单向关注,随后另一个人互相关注 LinkFowrard/LinkBackward -> LinkMutual 互相关注,随后其中一个人取消关注 LinkMutual -> LinkForward/LinkBackward
type Relation ¶
type Relation struct { // UserAlpha和UserBeta为两个存在关注关系的用户 // // 假设存在a=100,b=200,其实(100,2,200)和(200,-2,100)是相同的一组关系 // 所以此处需要作出一个规定:插入表中的alpha必须比beta小,从而保证(100,200)和(200,100)不会在数据库产生两条数据 // // 示例:(200,-2,100)==(100,2,200), (200,2,100)==(100,-2,200) // (200,-4,100)==(100,-4,200) Id uint64 `db:"id"` UserAlpha uint64 `db:"alpha"` // 用户A UserBeta uint64 `db:"beta"` // 用户B Link LinkStatus `db:"link"` // 用户的关注关系 Actime int64 `db:"actime"` // A首次关注B的时间,Unix时间戳 Bctime int64 `db:"bctime"` // B首次关注A的时间,Unix时间戳 Amtime int64 `db:"amtime"` // A改变对B的关注状态的时间,Unix时间戳 Bmtime int64 `db:"bmtime"` // B改变对A的关注状态的时间,Unix时间戳 }
type RelationDao ¶
type RelationDao struct {
// contains filtered or unexported fields
}
func NewRelationDao ¶
func NewRelationDao(db *xsql.DB, c *redis.Redis) *RelationDao
func (*RelationDao) CountUidFans ¶
获取关注uid的人数
func (*RelationDao) CountUidFollowings ¶
获取uid关注的人数
func (*RelationDao) FindAlphaGotLinked ¶
找到关注alpha的人
func (*RelationDao) FindAlphaLinkTo ¶
找到alpha关注的人
func (*RelationDao) FindBetaGotLinked ¶
找到关注beta的人
func (*RelationDao) FindBetaLinkTo ¶
找到beta关注的人
func (*RelationDao) FindByAlphaBeta ¶
func (*RelationDao) FindByAlphaBetaAndLink ¶
func (d *RelationDao) FindByAlphaBetaAndLink(ctx context.Context, a, b uint64, link LinkStatus, forUpdate bool) (*Relation, error)
func (*RelationDao) FindUidGotLinked ¶
func (d *RelationDao) FindUidGotLinked(ctx context.Context, uid, offset uint64, limit int) (uids []uint64, next uint64, more bool, err error)
找到关注uid的人
func (*RelationDao) FindUidLinkTo ¶
func (d *RelationDao) FindUidLinkTo(ctx context.Context, uid, offset uint64, limit int) (uids []uint64, next uint64, more bool, err error)
找到uid关注的人 (找到发出关注连接的用户存在的用户关系)
alpha=uid and link=Forward/Mutual or beta=uid and link=Backward/Mutual
func (*RelationDao) Insert ¶
func (d *RelationDao) Insert(ctx context.Context, r *Relation) error
插入/更新一条记录
func (*RelationDao) UpdateLink ¶
func (d *RelationDao) UpdateLink(ctx context.Context, r *Relation) error
type RelationSetting ¶
type RelationSetting struct { Uid uint64 `db:"uid"` NotShowFollowings int8 `db:"not_show_followings"` // 是否不展示关注的人 默认展示 ShowFans int8 `db:"show_fans"` // 是否展示粉丝 默认不展示 Ctime int64 `db:"ctime"` Mtime int64 `db:"mtime"` }
用户的关系设置
type RelationSettingDao ¶
type RelationSettingDao struct {
// contains filtered or unexported fields
}
func NewRelationSettingDao ¶
func NewRelationSettingDao(db *xsql.DB, c *redis.Redis) *RelationSettingDao
func (*RelationSettingDao) Get ¶
func (d *RelationSettingDao) Get(ctx context.Context, uid uint64) (*RelationSetting, error)
func (*RelationSettingDao) Insert ¶
func (d *RelationSettingDao) Insert(ctx context.Context, s *RelationSetting) error
func (*RelationSettingDao) Update ¶
func (d *RelationSettingDao) Update(ctx context.Context, s *RelationSetting) error
Click to show internal directories.
Click to hide internal directories.