Example #1
0
//Search reloads records in Caches in cachelist
//and returns slice of cache which matches query.
func Search(q string) Caches {
	reg, err := regexp.Compile(q)
	if err != nil {
		log.Println(err)
		return nil
	}
	var cnt []string
	err = db.DB.View(func(tx *bolt.Tx) error {
		return record.ForEach(tx,
			func(d *record.DB) error {
				if reg.Match([]byte(d.Body)) {
					cnt = append(cnt, d.Datfile)
				}
				return nil
			})
	})
	if err != nil {
		log.Println(err)
	}
	result := make([]*Cache, len(cnt))

	for i, rr := range cnt {
		result[i] = NewCache(rr)
	}
	return result
}
Example #2
0
//CleanRecords remove old or duplicates records for each Caches.
func CleanRecords() {
	err := db.DB.Update(func(tx *bolt.Tx) error {
		return record.ForEach(tx, func(rec *record.DB) error {
			if rec.Head.Stamp < time.Now().Unix()-cfg.SaveRecord {
				rec.Del(tx)
			}
			return nil
		})
	})
	if err != nil {
		log.Println(err)
	}
}
Example #3
0
//RemoveRemoved removes files in removed dir if old.
func RemoveRemoved() {
	if cfg.SaveRemoved <= 0 {
		return
	}
	err := db.DB.Update(func(tx *bolt.Tx) error {
		return record.ForEach(tx,
			func(rec *record.DB) error {
				if rec.Deleted && rec.Head.Stamp < time.Now().Unix()-cfg.SaveRemoved {
					rec.Del(tx)
				}
				return nil
			})
	})
	if err != nil {
		log.Println(err)
	}
}