Example #1
0
func (t *TiedotEngine) Insert(collectionName string, item Insertable) (uint64, error) {
	if len(item.ToM()) == 0 {
		log.Warningf("Failure: No data in item=%v", item.ToM())
		return 0, nil
	} else {
		log.V(3).Infof("Insertion into collection=%s item=%v",
			collectionName, item.ToM())
	}
	id, err := t.tiedot.Use(collectionName).Insert(item.ToM())
	if err != nil {
		log.Errorf("Failure inserting item=%v err=%s", item.ToM(), err.Error())
		return 0, err
	} else {
		log.V(6).Infof("Added item with ID=%d, item=%v", id, item.ToM())
		return id, nil
	}
}
Example #2
0
func incrHits(tde *kv.TiedotEngine, key string) uint64 {
	mu.Lock()
	defer mu.Unlock()
	short := new(Shortened)
	id, err := tde.Query(urlCollection).Equals(
		kv.Path{"Short"},
		base62.DecodeString(key),
	).OneInto(short)
	if err == kv.ErrNotFound {
		log.Warningf("Short URL %s not found", key)
		return 0
	} else if err != nil {
		log.Errorf("Failure getting shortened URL key=%s err:%v", key, err)
		return 0
	}

	short.HitCount++
	err = tde.Update(urlCollection, id, short)
	if err != nil {
		log.Error("Failure updating hitcount key=%s err=%s", key, err.Error())
		return 0
	}
	return short.HitCount
}