Esempio n. 1
0
File: topic.go Progetto: ovh/tat
// ListTags returns all tags on one topic
func ListTags(topic tat.Topic) ([]string, error) {
	var tags []string
	err := store.GetCMessages(topic.Collection).
		Find(bson.M{"topic": topic.Topic}).
		Distinct("tags", &tags)
	if err != nil {
		log.Errorf("Error while getting tags on topic %s, err:%s", topic.Topic, err.Error())
	}
	return tags, err
}
Esempio n. 2
0
File: topic.go Progetto: ovh/tat
// ListLabels returns all labels on one topic
func ListLabels(topic tat.Topic) ([]tat.Label, error) {
	var labels []tat.Label
	err := store.GetCMessages(topic.Collection).
		Find(bson.M{"topic": topic.Topic}).
		Distinct("labels", &labels)
	if err != nil {
		log.Errorf("Error while getting labels on topic %s, err:%s", topic.Topic, err.Error())
	}
	return labels, err
}
Esempio n. 3
0
File: topic.go Progetto: ovh/tat
// Truncate removes all messages in a topic
func Truncate(topic *tat.Topic) (int, error) {
	var changeInfo *mgo.ChangeInfo
	var err error
	if topic.Collection != "" && topic.Collection != store.CollectionDefaultMessages {
		changeInfo, err = store.GetCMessages(topic.Collection).RemoveAll(bson.M{})
	} else {
		changeInfo, err = store.GetCMessages(topic.Collection).RemoveAll(bson.M{"topic": topic.Topic})
		// TODO remove this after remove defaultMessagesCollection
		changeInfoOld, errOld := store.GetCMessages(topic.Collection).RemoveAll(bson.M{"topics": bson.M{"$in": [1]string{topic.Topic}}})
		if errOld != nil {
			log.Warnf("Error while removing message with topics attribute: %s", errOld)
		} else {
			log.Infof("Remove %d message with old way, select on topics attribute", changeInfoOld.Removed)
		}
	}

	if err != nil {
		return 0, err
	}
	cache.CleanMessagesLists(topic.Topic)
	return changeInfo.Removed, err
}