summary refs log tree commit diff stats
path: root/svc
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-06-13 20:18:05 -0400
committerBen Morrison <ben@gbmor.dev>2019-06-13 20:18:10 -0400
commit9c90526a24f32a00ad35073a09839189eb8aa007 (patch)
treecd8aa746d88512bb44a1c8e69f73a4e63e7af772 /svc
parent88dbd876a9635fa515ed29875816d05975272597 (diff)
downloadgetwtxt-9c90526a24f32a00ad35073a09839189eb8aa007.tar.gz
removed mutex from remoteRegistries
slices are safe to use concurrently already.
leaving as a struct for possible expansion later.
Diffstat (limited to 'svc')
-rw-r--r--svc/cache.go3
-rw-r--r--svc/db_test.go2
-rw-r--r--svc/init.go2
-rw-r--r--svc/leveldb.go6
-rw-r--r--svc/post.go2
-rw-r--r--svc/sqlite.go6
6 files changed, 0 insertions, 21 deletions
diff --git a/svc/cache.go b/svc/cache.go
index 7bad078..c51478b 100644
--- a/svc/cache.go
+++ b/svc/cache.go
@@ -20,7 +20,6 @@ import (
 // periodically scrape for new users. The remote registries
 // must have been added via POST like a user.
 type RemoteRegistries struct {
-	Mu   sync.RWMutex
 	List []string
 }
 
@@ -59,11 +58,9 @@ func cacheUpdate() {
 	}
 	twtxtCache.Mu.RUnlock()
 
-	remoteRegistries.Mu.RLock()
 	for _, v := range remoteRegistries.List {
 		errLog("Error refreshing local copy of remote registry data: ", twtxtCache.CrawlRemoteRegistry(v))
 	}
-	remoteRegistries.Mu.RUnlock()
 }
 
 // pingAssets checks if the local static assets
diff --git a/svc/db_test.go b/svc/db_test.go
index abf7626..3c0abdf 100644
--- a/svc/db_test.go
+++ b/svc/db_test.go
@@ -23,9 +23,7 @@ func Test_pushpullDatabase(t *testing.T) {
 
 	twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", "", net.ParseIP("127.0.0.1"), statusmap)
 
-	remoteRegistries.Mu.Lock()
 	remoteRegistries.List = append(remoteRegistries.List, "https://twtxt.tilde.institute/api/plain/users")
-	remoteRegistries.Mu.Unlock()
 
 	t.Run("Push to Database", func(t *testing.T) {
 		err := pushDB()
diff --git a/svc/init.go b/svc/init.go
index fe83145..edd081c 100644
--- a/svc/init.go
+++ b/svc/init.go
@@ -5,7 +5,6 @@ import (
 	"log"
 	"os"
 	"os/signal"
-	"sync"
 	"time"
 
 	"github.com/getwtxt/registry"
@@ -47,7 +46,6 @@ var twtxtCache = registry.NewIndex()
 
 // List of other registries submitted to this registry
 var remoteRegistries = &RemoteRegistries{
-	Mu:   sync.RWMutex{},
 	List: make([]string, 0),
 }
 
diff --git a/svc/leveldb.go b/svc/leveldb.go
index 655979a..7446dad 100644
--- a/svc/leveldb.go
+++ b/svc/leveldb.go
@@ -31,11 +31,9 @@ func (lvl *dbLevel) push() error {
 	}
 	twtxtCache.Mu.RUnlock()
 
-	remoteRegistries.Mu.RLock()
 	for k, v := range remoteRegistries.List {
 		dbBasket.Put([]byte("remote*"+string(k)), []byte(v))
 	}
-	remoteRegistries.Mu.RUnlock()
 
 	return lvl.db.Write(dbBasket, nil)
 }
@@ -51,9 +49,7 @@ func (lvl *dbLevel) pull() {
 		field := split[1]
 
 		if urls == "remote" {
-			remoteRegistries.Mu.Lock()
 			remoteRegistries.List = append(remoteRegistries.List, val)
-			remoteRegistries.Mu.Unlock()
 			continue
 		}
 
@@ -90,9 +86,7 @@ func (lvl *dbLevel) pull() {
 		twtxtCache.Mu.Unlock()
 	}
 
-	remoteRegistries.Mu.Lock()
 	remoteRegistries.List = dedupe(remoteRegistries.List)
-	remoteRegistries.Mu.Unlock()
 
 	iter.Release()
 	errLog("Error while pulling DB into registry cache: ", iter.Error())
diff --git a/svc/post.go b/svc/post.go
index 9050859..34ae92f 100644
--- a/svc/post.go
+++ b/svc/post.go
@@ -35,9 +35,7 @@ func apiPostUser(w http.ResponseWriter, r *http.Request) {
 
 	switch remoteRegistry {
 	case true:
-		remoteRegistries.Mu.Lock()
 		remoteRegistries.List = append(remoteRegistries.List, urls)
-		remoteRegistries.Mu.Unlock()
 
 		if err := twtxtCache.CrawlRemoteRegistry(urls); err != nil {
 			errHTTP(w, r, fmt.Errorf("error crawling remote registry: %v", err.Error()), http.StatusInternalServerError)
diff --git a/svc/sqlite.go b/svc/sqlite.go
index dd6d6de..b10e5ae 100644
--- a/svc/sqlite.go
+++ b/svc/sqlite.go
@@ -73,12 +73,10 @@ func (lite *dbSqlite) push() error {
 	}
 	twtxtCache.Mu.RUnlock()
 
-	remoteRegistries.Mu.RLock()
 	for _, e := range remoteRegistries.List {
 		_, err = txst.Exec(e, false, "REMOTE REGISTRY", "NULL")
 		errLog("", err)
 	}
-	remoteRegistries.Mu.RUnlock()
 
 	err = tx.Commit()
 	if err != nil {
@@ -110,9 +108,7 @@ func (lite *dbSqlite) pull() {
 		errLog("", rows.Scan(&uid, &urls, &isUser, &dataKey, &dBlob))
 
 		if !isUser {
-			remoteRegistries.Mu.Lock()
 			remoteRegistries.List = append(remoteRegistries.List, urls)
-			remoteRegistries.Mu.Unlock()
 			continue
 		}
 
@@ -142,7 +138,5 @@ func (lite *dbSqlite) pull() {
 	}
 	twtxtCache.Mu.Unlock()
 
-	remoteRegistries.Mu.Lock()
 	remoteRegistries.List = dedupe(remoteRegistries.List)
-	remoteRegistries.Mu.Unlock()
 }