compile tags regex once

This commit is contained in:
ston1th 2019-08-24 20:29:43 +02:00
commit 7686dfa474
5 changed files with 27 additions and 10 deletions

View file

@ -20,9 +20,9 @@ const (
pathPrefix = "path/"
)
func (db *DB) Reindex(path string, match []core.Tag) (err error) {
func (db *DB) Reindex(path string, match []core.RTag) (err error) {
if match == nil {
match, err = db.GetAllTags()
match, err = db.GetAllRTags()
if err != nil {
return
}
@ -53,7 +53,7 @@ func (db *DB) ReindexAll() (err error) {
if err != nil {
return
}
match, err := db.GetAllTags()
match, err := db.GetAllRTags()
if err != nil {
return
}

View file

@ -41,6 +41,17 @@ func (db *DB) GetAllTags() (tags []core.Tag, err error) {
return
}
func (db *DB) GetAllRTags() (rtags []core.RTag, err error) {
tags, err := db.GetAllTags()
if err != nil {
return
}
for _, v := range tags {
rtags = append(rtags, core.RTag{v.Name, regexp.MustCompile(v.Regex)})
}
return
}
func (db *DB) GetTags(name string) (t core.Tag, err error) {
err = db.store.Get(tagsPrefix+name, &t)
return