topics

package
v0.2.76 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CantWriteNew

func CantWriteNew(userId uint64, maxCount int64) bool

func Create

func Create(entity *Entity) error

func DecrementLike

func DecrementLike(entity Entity) int64

func DecrementPostFast

func DecrementPostFast(topicId uint64, posters []Poster, lastPostID uint64, lastPostedAt time.Time) error

func Delete

func Delete(entity *Entity) int64

func GetMapByIds

func GetMapByIds(ids []uint64) map[uint64]Entity

func GetMaxId

func GetMaxId() uint64

func GetPointerMapByIds

func GetPointerMapByIds(ids []uint64) map[uint64]*Entity

func IncrementLike

func IncrementLike(entity Entity) int64

func IncrementPostFast

func IncrementPostFast(topicId uint64, posters []Poster, lastPostID uint64, lastPostedAt time.Time) error

func IncrementPostFastWithDB added in v0.2.61

func IncrementPostFastWithDB(db *gorm.DB, topicId uint64, posters []Poster, lastPostID uint64, lastPostedAt time.Time) error

func IncrementViews

func IncrementViews(counts map[uint64]uint64) error

func MaxRankingID added in v0.2.74

func MaxRankingID(ctx context.Context) (uint64, error)

func PageForAdmin

func PageForAdmin(q AdminPageQuery) struct {
	Page     int
	PageSize int
	HasNext  bool
	Data     []Entity
}

func PageForModeration

func PageForModeration(q ModerationPageQuery) struct {
	Page     int
	PageSize int
	Total    int64
	HasNext  bool
	Data     []Entity
}

func RankingIDsAfter added in v0.2.74

func RankingIDsAfter(ctx context.Context, cursor, upper uint64, limit int) ([]uint64, error)

func ReservePostSequence

func ReservePostSequence(topicId uint64) (uint64, error)

func ReservePostSequenceWithDB added in v0.2.61

func ReservePostSequenceWithDB(db *gorm.DB, topicId uint64) (uint64, error)

func Save

func Save(entity *Entity) error

func SaveNoUpdate

func SaveNoUpdate(entity *Entity) error

func SaveOrCreateById

func SaveOrCreateById(entity *Entity) int64

func SaveRankScore added in v0.2.74

func SaveRankScore(ctx context.Context, id uint64, score int64) error

These writes deliberately use a table/map, bypassing read-only entity fields.

func SaveWithDB added in v0.2.74

func SaveWithDB(db *gorm.DB, entity *Entity) error

SaveWithDB leaves event publication to the caller after its transaction commits.

func SetPublishedAt added in v0.2.74

func SetPublishedAt(ctx context.Context, id uint64, at time.Time) error

func UpdatePinWeight

func UpdatePinWeight(id uint64, pinWeight int) error

func UpdateProcessStatus

func UpdateProcessStatus(id uint64, processStatus int8) error

Types

type AdminPageQuery

type AdminPageQuery struct {
	ModerationStatus string
	CategoryId       uint64
	Page, PageSize   int
	Search           string
	UserId           uint64
}

type Entity

type Entity struct {
	Id uint64 `` /* 396-byte string literal not displayed */
	// Ranking fields are read-only to ordinary model saves: stale topic snapshots
	// must never overwrite worker results or the first publication timestamp.
	RankScore   int64      `gorm:"column:rank_score;type:bigint;not null;default:0;->;index:idx_topics_list_rank,priority:3,sort:desc" json:"-"`
	PublishedAt *time.Time `gorm:"column:published_at;->" json:"-"`

	Title       string   `gorm:"column:title;type:varchar(512);not null;default:'';" json:"title"`
	CategoryIds []uint64 `gorm:"column:category_id;type:varchar(255);not null;default:'[]';serializer:json" json:"categoryIds"`
	// MainCategoryId is CategoryIds[0]. It is the only category that decides who
	// may read the topic. Remaining categories are public auxiliary tags; a
	// restricted category must be the topic's only category.
	MainCategoryId    uint64         `gorm:"column:main_category_id;type:bigint unsigned;not null;default:0;index:idx_topics_main_category;" json:"mainCategoryId"`
	UserId            uint64         `` /* 160-byte string literal not displayed */
	Status            int8           `` /* 264-byte string literal not displayed */
	ProcessStatus     int8           `` /* 279-byte string literal not displayed */
	ModerationStatus  string         `` /* 131-byte string literal not displayed */
	ModerationVersion uint64         `gorm:"column:moderation_version;type:bigint unsigned;not null;default:0" json:"-"`
	ModerationReason  string         `gorm:"column:moderation_reason;type:varchar(512);not null;default:''" json:"-"`
	ModeratedAt       *time.Time     `gorm:"column:moderated_at" json:"-"`
	LikeCount         uint64         `gorm:"column:like_count;type:bigint unsigned;not null;default:0;" json:"likeCount"`
	ViewCount         uint64         `` /* 133-byte string literal not displayed */
	PostCount         uint64         `gorm:"column:post_count;type:bigint unsigned;not null;default:0;" json:"postCount"`
	ReplyCount        uint64         `gorm:"column:reply_count;type:bigint unsigned;not null;default:0;" json:"replyCount"`
	PostSeq           uint64         `gorm:"column:post_seq;type:bigint unsigned;not null;default:0;" json:"postSeq"`
	FirstPostId       uint64         `gorm:"column:first_post_id;type:bigint unsigned;not null;default:0;" json:"firstPostId"`
	LastPostId        uint64         `gorm:"column:last_post_id;type:bigint unsigned;not null;default:0;" json:"lastPostId"`
	LastPostedAt      *time.Time     `gorm:"column:last_posted_at;index:idx_topics_last_posted,sort:desc;" json:"lastPostedAt"`
	PinWeight         int            `` /* 224-byte string literal not displayed */
	Excerpt           string         `gorm:"column:excerpt;type:varchar(255);not null;default:'';" json:"excerpt"`
	FirstImageURL     string         `gorm:"column:first_image_url;type:varchar(512);not null;default:'';" json:"firstImageUrl"`
	Posters           []Poster       `gorm:"column:posters;type:text;serializer:json" json:"posters"`
	CreatedAt         time.Time      `gorm:"column:created_at;autoCreateTime;<-:create;index:idx_topics_list_new,priority:3,sort:desc;" json:"createdAt"`
	UpdatedAt         time.Time      `` /* 246-byte string literal not displayed */
	DeletedAt         gorm.DeletedAt `json:"-"`
}

func Get

func Get(id uint64) (entity Entity)

func GetDraftsByUserId

func GetDraftsByUserId(userId uint64, limit int) ([]*Entity, error)

func GetForAdmin added in v0.2.75

func GetForAdmin(id uint64) (entity Entity)

func GetForRanking added in v0.2.74

func GetForRanking(ctx context.Context, id uint64) (Entity, error)

GetForRanking includes hidden/deleted topics so their scores can settle. Old decimal scores are not read during conversion to integer ranking.

func GetLatestPublished

func GetLatestPublished(limit int) (entities []*Entity, err error)

func GetLatestPublishedByUserId

func GetLatestPublishedByUserId(userId uint64, limit int) ([]*Entity, error)

func GetLatestPublishedByUserIdForAudience added in v0.2.61

func GetLatestPublishedByUserIdForAudience(userId uint64, limit int, readableCategoryIDs []uint64, filterAudience bool) ([]*Entity, error)

func GetLatestPublishedForAudience added in v0.2.61

func GetLatestPublishedForAudience(limit int, readableCategoryIDs []uint64, filterAudience bool) (entities []*Entity, err error)

func GetPublishedByUserBeforeId

func GetPublishedByUserBeforeId(userId uint64, beforeId uint64, limit int) ([]*Entity, error)

func GetPublishedByUserBeforeIdForAudience added in v0.2.61

func GetPublishedByUserBeforeIdForAudience(userId uint64, beforeId uint64, limit int, readableCategoryIDs []uint64, filterAudience bool) ([]*Entity, error)

func GetSimple

func GetSimple(id any) (entity Entity)

func QueryById

func QueryById(startId uint64, limit int) (entities []*Entity)

func (*Entity) GetPosters

func (itself *Entity) GetPosters() []Poster

func (*Entity) TableName

func (itself *Entity) TableName() string

type ModerationPageQuery

type ModerationPageQuery struct {
	Page, PageSize      int
	FilterProcessStatus bool
	ProcessStatus       int8
	CategoryIDs         []uint64
}

type PageQuery

type PageQuery struct {
	Page, PageSize      int
	Search              string
	UserId              uint64
	FilterStatus        bool
	CategoryId          uint64
	FilterAudience      bool
	ReadableCategoryIds []uint64
	Sort                string
}

type Poster

type Poster struct {
	UserID uint64 `json:"user_id"`
}

type TopicPage added in v0.2.61

type TopicPage struct {
	Page     int
	PageSize int
	HasNext  bool
	Data     []Entity
}

func Page

func Page(q PageQuery) TopicPage

func PageWithDB added in v0.2.61

func PageWithDB(conn *gorm.DB, q PageQuery) TopicPage

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL