示例#1
0
func (s *S) TestNow(c *C) {
	before := time.Now()
	time.Sleep(1e6)
	now := bson.Now()
	time.Sleep(1e6)
	after := time.Now()
	c.Assert(now.After(before) && now.Before(after), Equals, true, Commentf("now=%s, before=%s, after=%s", now, before, after))
}
示例#2
0
func (file *GridFile) completeWrite() {
	for file.wpending > 0 {
		debugf("GridFile %p: waiting for %d pending chunks to complete file write", file, file.wpending)
		file.c.Wait()
	}
	if file.err == nil {
		hexsum := hex.EncodeToString(file.wsum.Sum(nil))
		if file.doc.UploadDate.IsZero() {
			file.doc.UploadDate = bson.Now()
		}
		file.doc.MD5 = hexsum
		file.err = file.gfs.Files.Insert(file.doc)
		file.gfs.Chunks.EnsureIndexKey("files_id", "n")
	}
	if file.err != nil {
		file.gfs.Chunks.RemoveAll(bson.D{{"files_id", file.doc.Id}})
	}
}
示例#3
0
func aggregateDailyBest(rate *mgo.Collection) {
	countStar := bson.M{"$cond": []interface{}{bson.M{"$eq": []interface{}{"$is_star", true}}, 1, -1}}

	pipeline := []bson.M{
		{"$match": bson.M{"created_ad": bson.M{"$gte": bson.Now().AddDate(0, 0, -1)}}},
		{"$group": bson.M{
			"_id": "$post_id",
			"daily_star_count": bson.M{
				"$sum": countStar,
			},
		}},
		{"$project": bson.M{
			"_id":                     0,
			"query._id":               "$_id",
			"update.daily_star_count": "$daily_star_count",
		}},
	}
	log.Println("Update daily best post")
	updatePost(rate.Pipe(pipeline).Iter())
}