Пример #1
0
func (m *UserMgr) loadUsers() {
	var users []*User
	err := db.FindAll(DB, C_USER, nil, &users)
	if err != nil {
		panic(err)
	}
	log.Debug(len(users))
	for _, u := range users {
		m.Users[u.UserName] = u
	}
}
Пример #2
0
func (m *TopicMgr) loadTopics() {
	var topics []*Topic
	err := db.FindAll(DB, C_TOPIC, bson.M{"author": Blogger.UserName}, &topics)
	if err != nil {
		panic(err)
	}
	length := len(topics)
	m.IDs = make(INT32, 0, length)
	for _, topic := range topics {
		if !topic.NeedDelete.IsZero() {
			m.DeleteTopics[topic.ID] = topic
			continue
		}
		category := Blogger.GetCategoryByID(topic.CategoryID)
		if category == nil {
			topic.CategoryID = "default"
			category = Blogger.GetCategoryByID(topic.CategoryID)
		}
		topic.PCategory = category
		m.GroupByCategory[topic.CategoryID] = append(m.GroupByCategory[topic.CategoryID], topic.ID)
		var newTagIDs []string
		for _, id := range topic.TagIDs {
			if tag := Blogger.GetTagByID(id); tag != nil {
				topic.PTags = append(topic.PTags, tag)
				m.GroupByTag[id] = append(m.GroupByTag[id], topic.ID)
				newTagIDs = append(newTagIDs, id)
			}
		}
		topic.TagIDs = newTagIDs
		m.DoTopicUpdate(topic)
		m.Topics[topic.ID] = topic
		m.IDs = append(m.IDs, topic.ID)
		// archives
		date := topic.CreateTime.Format(helper.Layout_y_m)
		m.Archives[date] = append(m.Archives[date], topic.ID)
	}
	sort.Sort(m.IDs)
	for k, _ := range m.GroupByCategory {
		sort.Sort(m.GroupByCategory[k])
	}
	for k, _ := range m.GroupByTag {
		sort.Sort(m.GroupByTag[k])
	}
}