Use gorm connection pool

This commit is contained in:
Juan Font Alonso 2021-07-04 21:56:13 +02:00
parent d4b27fd54b
commit ecf258f995
2 changed files with 3 additions and 18 deletions

View file

@ -166,13 +166,8 @@ func (h *Headscale) expandAlias(s string) (*[]string, error) {
// This will have HORRIBLE performance.
// We need to change the data model to better store tags
db, err := h.db()
if err != nil {
log.Printf("Cannot open DB: %s", err)
return nil, err
}
machines := []Machine{}
if err = db.Where("registered").Find(&machines).Error; err != nil {
if err := h.db.Where("registered").Find(&machines).Error; err != nil {
return nil, err
}
ips := []string{}

View file

@ -86,11 +86,6 @@ func (s *Suite) TestPortNamespace(c *check.C) {
pak, err := h.CreatePreAuthKey(n.Name, false, false, nil)
c.Assert(err, check.IsNil)
db, err := h.db()
if err != nil {
c.Fatal(err)
}
_, err = h.GetMachine("testnamespace", "testmachine")
c.Assert(err, check.NotNil)
ip, _ := h.getAvailableIP()
@ -106,7 +101,7 @@ func (s *Suite) TestPortNamespace(c *check.C) {
IPAddress: ip.String(),
AuthKeyID: uint(pak.ID),
}
db.Save(&m)
h.db.Save(&m)
err = h.LoadACLPolicy("./tests/acls/acl_policy_basic_namespace_as_user.hujson")
c.Assert(err, check.IsNil)
@ -131,11 +126,6 @@ func (s *Suite) TestPortGroup(c *check.C) {
pak, err := h.CreatePreAuthKey(n.Name, false, false, nil)
c.Assert(err, check.IsNil)
db, err := h.db()
if err != nil {
c.Fatal(err)
}
_, err = h.GetMachine("testnamespace", "testmachine")
c.Assert(err, check.NotNil)
ip, _ := h.getAvailableIP()
@ -151,7 +141,7 @@ func (s *Suite) TestPortGroup(c *check.C) {
IPAddress: ip.String(),
AuthKeyID: uint(pak.ID),
}
db.Save(&m)
h.db.Save(&m)
err = h.LoadACLPolicy("./tests/acls/acl_policy_basic_groups.hujson")
c.Assert(err, check.IsNil)