示例#1
0
func (self *BaseModel) PrepareSave() {
	if !self.Id.Valid() {
		self.Id = bson.NewObjectId()
	}

	if !(self.CreatedOn > 0) {
		self.CreatedOn = utils.EpochNow()
	}

	self.ModifiedOn = utils.EpochNow()
}
示例#2
0
func Throttled(pending_item *db.PendingItem) bool {
	var query utils.M = make(utils.M)

	query["org"] = pending_item.Organization
	query["app_name"] = pending_item.AppName
	query["topic"] = pending_item.Topic
	query["user"] = pending_item.User
	query["created_by"] = pending_item.CreatedBy
	query["created_on"] = utils.M{"$gt": utils.EpochNow() - LATENCY}
	query["entity"] = pending_item.Entity

	count := db.Conn.Count(db.SentCollection, query)

	return count > 0
}
示例#3
0
func Save(args *RequestArgs) error {
	user := args.User
	appName := args.AppName
	org := args.Organization

	stats_query := utils.M{
		"user":     user,
		"app_name": appName,
		"org":      org,
	}

	save_doc := utils.M{
		"user":      user,
		"app_name":  appName,
		"org":       org,
		"timestamp": utils.EpochNow(),
	}

	return db.Conn.Upsert(db.StatsCollection, stats_query, save_doc)
}
示例#4
0
func (self *MConn) Update(table string, query utils.M, doc utils.M) error {

	//Create a Session Copy and be responsible for Closing it.
	session := self.Session.Copy()
	db := session.DB(self.Dbname)
	defer session.Close()

	coll := db.C(table)
	var update_err error
	if len(doc) == 0 {
		update_err = errors.New(
			"Empty Update is blocked. Refer to " +
				"https://github.com/Simversity/blackjack/issues/1051",
		)
	} else {
		AlterDoc(&doc, "$set", utils.M{"updated_on": utils.EpochNow()})
		_, update_err = coll.UpdateAll(query, doc)
	}

	if update_err != nil {
		log.Println("Error Updating:", table, update_err)
	}
	return update_err
}