MCPcopy
hub / github.com/tinode/chat / initTopicGrp

Function initTopicGrp

server/init_topic.go:628–672  ·  view source on GitHub ↗

Initialize existing group topic. There is a race condition when two users attempt to load the same topic at the same time. It's prevented at hub level.

(t *Topic)

Source from the content-addressed store, hash-verified

626// Initialize existing group topic. There is a race condition when two users attempt to load
627// the same topic at the same time. It's prevented at hub level.
628func initTopicGrp(t *Topic) error {
629 t.cat = types.TopicCatGrp
630
631 // TODO(gene): check and validate topic name
632 stopic, err := store.Topics.Get(t.name)
633 if err != nil {
634 return err
635 } else if stopic == nil {
636 return types.ErrTopicNotFound
637 }
638
639 if err = t.loadSubscribers(); err != nil {
640 return err
641 }
642
643 t.isChan = stopic.UseBt
644
645 // t.owner is set by loadSubscriptions
646
647 t.accessAuth = stopic.Access.Auth
648 t.accessAnon = stopic.Access.Anon
649
650 // Assign tags & auxiliary data.
651 t.tags = stopic.Tags
652 t.aux = stopic.Aux
653
654 t.public = stopic.Public
655 t.trusted = stopic.Trusted
656
657 t.created = stopic.CreatedAt
658 t.updated = stopic.UpdatedAt
659 if !stopic.TouchedAt.IsZero() {
660 t.touched = stopic.TouchedAt
661 }
662 t.lastID = stopic.SeqId
663 t.delID = stopic.DelId
664 t.subCnt = stopic.SubCnt
665
666 // Initialize channel for receiving session online updates.
667 t.supd = make(chan *sessionUpdate, 32)
668
669 t.xoriginal = t.name // topic may have been loaded by a channel reader; make sure it's grpXXX, not chnXXX.
670
671 return nil
672}
673
674// Initialize system topic. System topic is a singleton, always in memory.
675func initTopicSys(t *Topic) error {

Callers 1

topicInitFunction · 0.85

Calls 3

loadSubscribersMethod · 0.80
GetMethod · 0.65
IsZeroMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…