Ejemplo n.º 1
0
// Wrapper to get hold of a factoid collection handle
func Collection(dbh *db.Database, l logging.Logger) *FactoidCollection {
	fc := &FactoidCollection{
		Collection: dbh.C(COLLECTION),
		seen:       make(map[string][]bson.ObjectId),
		l:          l,
	}
	err := fc.EnsureIndex(mgo.Index{Key: []string{"key"}})
	if err != nil {
		l.Error("Couldn't create index on sp0rkle.factoids: %v", err)
	}
	return fc
}
Ejemplo n.º 2
0
Archivo: urls.go Proyecto: b33f/sp0rkle
func Collection(dbh *db.Database, l logging.Logger) *UrlCollection {
	uc := &UrlCollection{dbh.C(collection), l}
	err := uc.EnsureIndex(mgo.Index{Key: []string{"url"}, Unique: true})
	if err != nil {
		l.Error("Couldn't create url index on sp0rkle.urls: %s", err)
	}
	for _, idx := range []string{"cachedas", "shortened"} {
		err := uc.EnsureIndex(mgo.Index{Key: []string{idx}})
		if err != nil {
			l.Error("Couldn't create %s index on sp0rkle.urls: %s", idx, err)
		}
	}
	return uc
}
Ejemplo n.º 3
0
Archivo: seen.go Proyecto: b33f/sp0rkle
func Collection(dbh *db.Database, l logging.Logger) *SeenCollection {
	sc := &SeenCollection{
		Collection: dbh.C(COLLECTION),
		l:          l,
	}
	err := sc.EnsureIndex(mgo.Index{
		Key:    []string{"key", "action"},
		Unique: true,
	})
	if err != nil {
		l.Error("Couldn't create index on sp0rkle.seen: %v", err)
	}
	err = sc.EnsureIndexKey("key")
	if err != nil {
		l.Error("Couldn't create index on sp0rkle.seen: %v", err)
	}
	return sc
}
Ejemplo n.º 4
0
func Collection(dbh *db.Database, l logging.Logger) *QuoteCollection {
	qc := &QuoteCollection{
		Collection: dbh.C(COLLECTION),
		seen:       make(map[string][]bson.ObjectId),
		maxQID:     1,
		l:          l,
	}
	err := qc.EnsureIndex(mgo.Index{Key: []string{"qid"}, Unique: true})
	if err != nil {
		l.Error("Couldn't create index on sp0rkle.quotes: %v", err)
	}

	var res Quote
	if err := qc.Find(bson.M{}).Sort("-qid").One(&res); err == nil {
		qc.maxQID = int32(res.QID)
	}
	return qc
}