func (m *RequestManage) Saver() { t := time.NewTicker(time.Minute * 10) for { select { case request := <-m.Ch: err := db.Insert(DB, C_REQUEST, request) if err != nil { log.Error(err) } case <-t.C: ManageData.loadData(TODAY) } } }
func (m *TopicMgr) AddTopic(topic *Topic) error { m.lock.Lock() defer m.lock.Unlock() if err := db.Insert(DB, C_TOPIC, topic); err != nil { return err } category := Blogger.GetCategoryByID(topic.CategoryID) if category == nil { topic.CategoryID = "default" category = Blogger.GetCategoryByID(topic.CategoryID) } m.GroupByCategory[topic.CategoryID] = append(m.GroupByCategory[topic.CategoryID], topic.ID) topic.PCategory = category category.addCount() for _, id := range topic.TagIDs { if tag := Blogger.GetTagByID(id); tag != nil { m.GroupByTag[id] = append(m.GroupByTag[id], topic.ID) topic.PTags = append(topic.PTags, tag) tag.addCount() } else { newtag := NewTag() newtag.ID = id newtag.Extra = "/tag/" + id newtag.Text = id m.GroupByTag[id] = append(m.GroupByTag[id], topic.ID) topic.PTags = append(topic.PTags, newtag) Blogger.AddTag(newtag) } } m.Topics[topic.ID] = topic m.IDs = append(m.IDs, topic.ID) sort.Sort(m.IDs) m.AddArchive(topic) m.DoTopicUpdate(topic) return nil }