commit before applying 2p patch

This commit is contained in:
2020-04-04 18:16:37 -07:00
parent 4c33b5dd0e
commit 70faf517f3
8 changed files with 79 additions and 12 deletions

View File

@@ -27,6 +27,7 @@ func (m *Manager) SaveInstance(i *instance.Instance) error {
Identified: i.Identified,
Implementation: i.Implementation,
NextFetch: i.NextFetch,
LastError: i.LastError,
NodeInfoURL: i.NodeInfoURL,
ServerImplementationString: i.ServerImplementationString,
ServerVersionString: i.ServerVersionString,
@@ -49,6 +50,7 @@ func (m *Manager) SaveInstance(i *instance.Instance) error {
ei.Fetching = i.Fetching
ei.HighestID = i.HighestID
ei.Hostname = i.Hostname
ei.LastError = i.LastError
ei.Identified = i.Identified
ei.Implementation = string(i.Implementation)
ei.NextFetch = i.NextFetch
@@ -56,7 +58,6 @@ func (m *Manager) SaveInstance(i *instance.Instance) error {
ei.ServerImplementationString = i.ServerImplementationString
ei.ServerVersionString = i.ServerVersionString
ei.SuccessCount = i.SuccessCount
r := m.db.Save(&ei)
return r.Error
}
@@ -77,6 +78,7 @@ func (m *Manager) ListInstances() ([]*instance.Instance, error) {
x.Fetching = i.Fetching
x.HighestID = i.HighestID
x.Hostname = i.Hostname
x.LastError = i.LastError
x.Identified = i.Identified
x.Implementation = i.Implementation
x.NextFetch = i.NextFetch

View File

@@ -21,7 +21,7 @@ type StoredToot struct {
Content []byte
TextContent []byte
URL string
Hostname string
Hostname string `gorm:"index:hostnameindex"`
}
type APInstance struct {
@@ -34,6 +34,7 @@ type APInstance struct {
Identified bool
Fetching bool
Disabled bool
LastError string
Implementation string
NextFetch time.Time
NodeInfoURL string

24
database/readshortcuts.go Normal file
View File

@@ -0,0 +1,24 @@
package database
import (
"github.com/google/uuid"
)
func (m *Manager) TootCountForHostname(hostname string) (uint, error) {
var c uint
e := m.db.Model(&StoredToot{}).Where("hostname = ?", hostname).Count(&c)
if e.Error != nil {
return 0, e.Error
} else {
return c, nil
}
}
func (m *Manager) GetAPInstanceFromUUID(uuid *uuid.UUID) (*APInstance, error) {
var i APInstance
e := m.db.Model(&APInstance{}).Where("uuid = ?", uuid).First(&i)
if e.Error != nil {
return nil, e.Error
}
return &i, nil
}