Skip to content

Commit

Permalink
fixed panic when load indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
hengfeiyang committed May 27, 2022
1 parent 50a5783 commit a62265b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
4 changes: 0 additions & 4 deletions pkg/auth/cached_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ import (

var ZINC_CACHED_USERS cachedUsers

func init() {
ZINC_CACHED_USERS.users = make(map[string]*meta.User)
}

type cachedUsers struct {
users map[string]*meta.User
lock sync.RWMutex
Expand Down
6 changes: 5 additions & 1 deletion pkg/auth/firststart.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ import (
"os"

"github.com/rs/zerolog/log"

"github.com/zinclabs/zinc/pkg/meta"
)

func init() {
// init cache users
ZINC_CACHED_USERS.users = make(map[string]*meta.User)
// init first start
firstStart, err := isFirstStart()
if err != nil {
log.Print(err)
Expand All @@ -44,7 +49,6 @@ func isFirstStart() (bool, error) {
return true, nil
}

// cache users
for _, user := range users {
ZINC_CACHED_USERS.Set(user.ID, user)
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/core/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/blugelabs/bluge"
"github.com/blugelabs/bluge/analysis"
"github.com/goccy/go-json"
"github.com/rs/zerolog/log"

"github.com/zinclabs/zinc/pkg/config"
"github.com/zinclabs/zinc/pkg/meta"
Expand All @@ -45,12 +44,6 @@ type Index struct {
Writer *bluge.Writer `json:"-"`
}

func init() {
if err := LoadZincIndexesFromMetadata(); err != nil {
log.Error().Err(err).Msgf("Error loading index")
}
}

// BuildBlugeDocumentFromJSON returns the bluge document for the json document. It also updates the mapping for the fields if not found.
// If no mappings are found, it creates te mapping for all the encountered fields. If mapping for some fields is found but not for others
// then it creates the mapping for the missing fields.
Expand Down
13 changes: 9 additions & 4 deletions pkg/core/indexlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@ package core

import (
"sync"

"github.com/rs/zerolog/log"
)

var ZINC_INDEX_LIST IndexList

func init() {
ZINC_INDEX_LIST.Indexes = make(map[string]*Index)
}

type IndexList struct {
Indexes map[string]*Index
lock sync.RWMutex
}

func init() {
ZINC_INDEX_LIST.Indexes = make(map[string]*Index)
if err := LoadZincIndexesFromMetadata(); err != nil {
log.Error().Err(err).Msgf("Error loading index")
}
}

func (t *IndexList) Add(index *Index) {
t.lock.Lock()
t.Indexes[index.Name] = index
Expand Down

0 comments on commit a62265b

Please sign in to comment.