Skip to content

Commit

Permalink
fix: (database) indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
tyzbit committed May 3, 2023
1 parent ebe18b2 commit e26a117
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Otherwise, it will save stats to a local sqlite database at `/var/go-discord-arc
| Variable | Value(s) |
| :---------------- | :------------------------------------------------------------------------------------- |
| ADMINISTRATOR_IDS | Comma separated IDs of users allowed to use administrator commands |
| DB_DATABASE | Database name for database |
| DB_NAME | Database name for database |
| DB_HOST | Hostname for database |
| DB_PASSWORD | Password for database user |
| DB_USER | Username for database user |
Expand Down
12 changes: 6 additions & 6 deletions bot/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// requires our attention
type MessageEvent struct {
CreatedAt time.Time
UUID string `gorm:"primaryKey,uniqueIndex"`
UUID string `gorm:"primaryKey" gorm:"uniqueIndex"`
AuthorId string `gorm:"index"`
AuthorUsername string
MessageId string
Expand All @@ -23,7 +23,7 @@ type MessageEvent struct {
// A InteractionEvent when a user interacts with an Embed
type InteractionEvent struct {
CreatedAt time.Time
UUID string `gorm:"primaryKey,uniqueIndex"`
UUID string `gorm:"primaryKey" gorm:"uniqueIndex"`
UserID string `gorm:"index"`
Username string
InteractionId string
Expand All @@ -36,7 +36,7 @@ type InteractionEvent struct {
// Every successful ArchiveEventEvent will come from a message
type ArchiveEventEvent struct {
CreatedAt time.Time
UUID string `gorm:"primaryKey,uniqueIndex"`
UUID string `gorm:"primaryKey;uniqueIndex"`
AuthorId string
AuthorUsername string
ChannelId string
Expand All @@ -50,13 +50,13 @@ type ArchiveEventEvent struct {
// the Archiver API
type ArchiveEvent struct {
CreatedAt time.Time
UUID string `gorm:"primaryKey,uniqueIndex"`
UUID string `gorm:"primaryKey;uniqueIndex"`
ArchiveEventEventUUID string
ServerID string `gorm:"index"`
ServerName string
RequestURL string `gorm:"index"`
RequestURL string
RequestDomainName string `gorm:"index"`
ResponseURL string `gorm:"index"`
ResponseURL string
ResponseDomainName string `gorm:"index"`
Cached bool
}
Expand Down
6 changes: 3 additions & 3 deletions bot/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

type ServerRegistration struct {
DiscordId string `gorm:"primaryKey,uniqueIndex"`
DiscordId string `gorm:"primaryKey;uniqueIndex"`
Name string
UpdatedAt time.Time
JoinedAt time.Time
Expand All @@ -19,7 +19,7 @@ type ServerRegistration struct {
}

type ServerConfig struct {
DiscordId string `gorm:"primaryKey,uniqueIndex" pretty:"Server ID"`
DiscordId string `gorm:"primaryKey;uniqueIndex" pretty:"Server ID"`
Name string `pretty:"Server Name" gorm:"default:default"`
ArchiveEnabled sql.NullBool `pretty:"Bot enabled" gorm:"default:true"`
AlwaysArchiveFirst sql.NullBool `pretty:"Archive the page first (slower)" gorm:"default:false"`
Expand Down Expand Up @@ -83,7 +83,7 @@ func (bot *ArchiverBot) registerOrUpdateServer(g *discordgo.Guild, delete bool)
// updates the DB as to whether or not it's active
func (bot *ArchiverBot) updateInactiveRegistrations(activeGuilds []*discordgo.Guild) {
var sr []ServerRegistration
bot.DB.Find(&sr)
bot.DB.Model([]ServerRegistration{}).Find(&sr)

// Check all registrations for whether or not the server is active
for _, reg := range sr {
Expand Down

0 comments on commit e26a117

Please sign in to comment.