made indexAll and retagAll atomic and faster
This commit is contained in:
parent
1fdacd8a93
commit
5649acf6a8
6 changed files with 131 additions and 64 deletions
|
|
@ -2,11 +2,7 @@
|
|||
|
||||
package db
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"git.giftfish.de/ston1th/docstore/pkg/core"
|
||||
"git.giftfish.de/ston1th/docstore/pkg/log"
|
||||
)
|
||||
import "git.giftfish.de/ston1th/docstore/pkg/core"
|
||||
|
||||
const (
|
||||
// schema:
|
||||
|
|
@ -19,55 +15,6 @@ const (
|
|||
pathPrefix = "path/"
|
||||
)
|
||||
|
||||
func (db *DB) Retag(path string, tags core.RTags) (err error) {
|
||||
if tags == nil {
|
||||
tags, err = db.GetAllRTags()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
id, err := db.GetID(path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
log.Debugf("db: retagging: %s", path)
|
||||
doc, err := db.Index.Get(id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
doc.Tags = tags.Match(doc.Text)
|
||||
err = db.Index.Update(id, doc)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return db.SetTag(path, doc.Tags)
|
||||
}
|
||||
|
||||
func (db *DB) RetagAll() (err error) {
|
||||
var paths []string
|
||||
err = db.store.ForEachPrefix(idPrefix, func(k string, _ []byte) error {
|
||||
paths = append(paths, k)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
tags, err := db.GetAllRTags()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, p := range paths {
|
||||
e := db.Retag(p, tags)
|
||||
if e != nil {
|
||||
if err == nil {
|
||||
err = errors.New("retagAll had errors")
|
||||
}
|
||||
log.Printf("db: error retagging %s: %s", p, e)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (db *DB) GetPaths(res core.Results) {
|
||||
for i, v := range res {
|
||||
err := db.store.Get(pathPrefix+v.ID, &res[i].Path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue