Beispiel #1
0
func (p *RelationsCache) PutRelation(relation *element.Relation) error {
	keyBuf := idToKeyBuf(relation.Id)
	data, err := binary.MarshalRelation(relation)
	if err != nil {
		return err
	}
	return p.db.Put(p.wo, keyBuf, data)
}
Beispiel #2
0
func (p *RelationsCache) PutRelations(rels []element.Relation) error {
	batch := levigo.NewWriteBatch()
	defer batch.Close()

	for _, rel := range rels {
		if len(rel.Tags) == 0 {
			continue
		}
		keyBuf := idToKeyBuf(rel.Id)
		data, err := binary.MarshalRelation(&rel)
		if err != nil {
			return err
		}
		batch.Put(keyBuf, data)
	}
	return p.db.Write(p.wo, batch)
}