Skip to content

Commit

Permalink
resolve cache issue by disabling cache
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Jun 7, 2023
1 parent 11914d1 commit 76e651d
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions file.go
Expand Up @@ -18,36 +18,37 @@ var searchToFileMatchesCache = map[string][]string{}
var searchToFileMatchesCacheMutex = sync.Mutex{}

func FindFiles(query string) chan *gocodewalker.File {
searchToFileMatchesCacheMutex.Lock()
defer searchToFileMatchesCacheMutex.Unlock()

// get the keys for the cache
var keys []string
for k := range searchToFileMatchesCache {
keys = append(keys, k)
}

// clear from the cache anything longer than the search since its will not help us
for _, k := range keys {
if len(k) > len(query) || query[0] != k[0] { // if cached is longer OR the first char does not match...
delete(searchToFileMatchesCache, k)
}
}

// check if the files we expect are in the cache...
files := make(chan *gocodewalker.File, 100000)
for i := len(query); i > 0; i-- {
r, ok := searchToFileMatchesCache[query[:i]]
if ok {
go func() {
for _, f := range r {
files <- &gocodewalker.File{Location: f}
}
close(files)
}()
return files
}
}
// TODO enable this again as it seems to have issues
//searchToFileMatchesCacheMutex.Lock()
//defer searchToFileMatchesCacheMutex.Unlock()
//
//// get the keys for the cache
//var keys []string
//for k := range searchToFileMatchesCache {
// keys = append(keys, k)
//}
//
//// clear from the cache anything longer than the search since its will not help us
//for _, k := range keys {
// if len(k) > len(query) || query[0] != k[0] { // if cached is longer OR the first char does not match...
// delete(searchToFileMatchesCache, k)
// }
//}
//
//// check if the files we expect are in the cache...
//files := make(chan *gocodewalker.File, 100000)
//for i := len(query); i > 0; i-- {
// r, ok := searchToFileMatchesCache[query[:i]]
// if ok {
// go func() {
// for _, f := range r {
// files <- &gocodewalker.File{Location: f}
// }
// close(files)
// }()
// return files
// }
//}

return walkFiles()
}
Expand Down

0 comments on commit 76e651d

Please sign in to comment.