Documentation
¶
Index ¶
- Variables
- func InitTable(db *gorm.DB) error
- type Collection
- type GORMInteractiveDAO
- func (dao *GORMInteractiveDAO) BatchIncrReadCnt(ctx context.Context, bizs []string, ids []int64) error
- func (dao *GORMInteractiveDAO) DeleteLikeInfo(ctx context.Context, biz string, bizId, uid int64) error
- func (dao *GORMInteractiveDAO) Get(ctx context.Context, biz string, bizId int64) (Interactive, error)
- func (dao *GORMInteractiveDAO) GetByIds(ctx context.Context, biz string, ids []int64) ([]Interactive, error)
- func (dao *GORMInteractiveDAO) GetCollectionInfo(ctx context.Context, biz string, bizId, uid int64) (UserCollectionBiz, error)
- func (dao *GORMInteractiveDAO) GetLikeInfo(ctx context.Context, biz string, bizId, uid int64) (UserLikeBiz, error)
- func (dao *GORMInteractiveDAO) IncrReadCnt(ctx context.Context, biz string, bizId int64) error
- func (dao *GORMInteractiveDAO) InsertCollectionBiz(ctx context.Context, cb UserCollectionBiz) error
- func (dao *GORMInteractiveDAO) InsertLikeInfo(ctx context.Context, biz string, bizId, uid int64) error
- type Interactive
- type InteractiveDAO
- type UserCollectionBiz
- type UserLikeBiz
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrDataNotFound = gorm.ErrRecordNotFound
Functions ¶
Types ¶
type Collection ¶
type Collection struct {
Id int64 `gorm:"primaryKey,autoIncrement"`
Name string `gorm:"type=varchar(1024)"`
Uid int64 `gorm:""`
Ctime int64
Utime int64
}
Collection 收藏夹
type GORMInteractiveDAO ¶
type GORMInteractiveDAO struct {
// contains filtered or unexported fields
}
func (*GORMInteractiveDAO) BatchIncrReadCnt ¶
func (*GORMInteractiveDAO) DeleteLikeInfo ¶
func (*GORMInteractiveDAO) Get ¶
func (dao *GORMInteractiveDAO) Get(ctx context.Context, biz string, bizId int64) (Interactive, error)
func (*GORMInteractiveDAO) GetByIds ¶
func (dao *GORMInteractiveDAO) GetByIds(ctx context.Context, biz string, ids []int64) ([]Interactive, error)
func (*GORMInteractiveDAO) GetCollectionInfo ¶
func (dao *GORMInteractiveDAO) GetCollectionInfo(ctx context.Context, biz string, bizId, uid int64) (UserCollectionBiz, error)
func (*GORMInteractiveDAO) GetLikeInfo ¶
func (dao *GORMInteractiveDAO) GetLikeInfo(ctx context.Context, biz string, bizId, uid int64) (UserLikeBiz, error)
func (*GORMInteractiveDAO) IncrReadCnt ¶
IncrReadCnt 是一个插入或者更新语义
func (*GORMInteractiveDAO) InsertCollectionBiz ¶
func (dao *GORMInteractiveDAO) InsertCollectionBiz(ctx context.Context, cb UserCollectionBiz) error
InsertCollectionBiz 插入收藏记录,并且更新计数
func (*GORMInteractiveDAO) InsertLikeInfo ¶
type Interactive ¶
type Interactive struct {
Id int64 `gorm:"primaryKey,autoIncrement"`
BizId int64 `gorm:"uniqueIndex:biz_type_id"` // 业务标识符,联合唯一索引
Biz string `gorm:"type:varchar(128);uniqueIndex:biz_type_id"`
ReadCnt int64
CollectCnt int64
// 直接在 LikeCnt 上创建一个索引
// 1. 而后查询前 100 的,直接就命中索引,这样你前 100 最多 100 次回表
// SELECT * FROM interactives ORDER BY like_cnt limit 0, 100
// 还有一种优化思路是
// SELECT * FROM interactives WHERE like_cnt > 1000 ORDER BY like_cnt limit 0, 100
// 2. 如果你只需要 biz_id 和 biz_type,你就创建联合索引 <like_cnt, biz_id, biz>
LikeCnt int64
Ctime int64
Utime int64
}
func (Interactive) ID ¶
func (i Interactive) ID() int64
type InteractiveDAO ¶
type InteractiveDAO interface {
IncrReadCnt(ctx context.Context, biz string, bizId int64) error
InsertLikeInfo(ctx context.Context, biz string, bizId, uid int64) error
GetLikeInfo(ctx context.Context, biz string, bizId, uid int64) (UserLikeBiz, error)
DeleteLikeInfo(ctx context.Context, biz string, bizId, uid int64) error
Get(ctx context.Context, biz string, bizId int64) (Interactive, error)
InsertCollectionBiz(ctx context.Context, cb UserCollectionBiz) error
GetCollectionInfo(ctx context.Context, biz string, bizId, uid int64) (UserCollectionBiz, error)
BatchIncrReadCnt(ctx context.Context, bizs []string, ids []int64) error
GetByIds(ctx context.Context, biz string, ids []int64) ([]Interactive, error)
}
func NewGORMInteractiveDAO ¶
func NewGORMInteractiveDAO(db *gorm.DB) InteractiveDAO
type UserCollectionBiz ¶
type UserCollectionBiz struct {
Id int64 `gorm:"primaryKey,autoIncrement"`
// 收藏夹 ID
// 作为关联关系中的外键,我们这里需要索引
Cid int64 `gorm:"index"`
BizId int64 `gorm:"uniqueIndex:biz_type_id_uid"`
Biz string `gorm:"type:varchar(128);uniqueIndex:biz_type_id_uid"`
// 这算是一个冗余,因为正常来说,
// 只需要在 Collection 中维持住 Uid 就可以
Uid int64 `gorm:"uniqueIndex:biz_type_id_uid"`
Ctime int64
Utime int64
}
UserCollectionBiz 收藏的东西
type UserLikeBiz ¶
type UserLikeBiz struct {
Id int64 `gorm:"primaryKey,autoIncrement"`
// 三个构成唯一索引
BizId int64 `gorm:"uniqueIndex:biz_type_id_uid"`
Biz string `gorm:"type:varchar(128);uniqueIndex:biz_type_id_uid"`
Uid int64 `gorm:"uniqueIndex:biz_type_id_uid"`
// 依旧是只在 DB 层面生效的状态
// 1- 有效,0-无效。软删除的用法
Status uint8
Ctime int64
Utime int64
}
UserLikeBiz 命名无能,用户点赞的某个东西
Click to show internal directories.
Click to hide internal directories.