Remove deleted_at

main
Max Ignatenko 2024-02-15 20:29:08 +00:00
parent 8561d90caf
commit 8313c74482
4 changed files with 17 additions and 9 deletions

View File

@ -151,7 +151,7 @@ func (c *Consumer) checkForCursorReset(ctx context.Context, seq int64) error {
func (c *Consumer) resetCursor(ctx context.Context, seq int64) error { func (c *Consumer) resetCursor(ctx context.Context, seq int64) error {
zerolog.Ctx(ctx).Warn().Str("pds", c.remote.Host).Msgf("Cursor reset: %d -> %d", c.remote.Cursor, seq) zerolog.Ctx(ctx).Warn().Str("pds", c.remote.Host).Msgf("Cursor reset: %d -> %d", c.remote.Cursor, seq)
err := c.db.Model(&c.remote). err := c.db.Model(&c.remote).
Where(&pds.PDS{Model: gorm.Model{ID: c.remote.ID}}). Where(&pds.PDS{ID: c.remote.ID}).
Updates(&pds.PDS{FirstCursorSinceReset: seq}).Error Updates(&pds.PDS{FirstCursorSinceReset: seq}).Error
if err != nil { if err != nil {
return fmt.Errorf("updating FirstCursorSinceReset: %w", err) return fmt.Errorf("updating FirstCursorSinceReset: %w", err)
@ -167,7 +167,7 @@ func (c *Consumer) updateCursor(ctx context.Context, seq int64) error {
} }
err := c.db.Model(&c.remote). err := c.db.Model(&c.remote).
Where(&pds.PDS{Model: gorm.Model{ID: c.remote.ID}}). Where(&pds.PDS{ID: c.remote.ID}).
Updates(&pds.PDS{Cursor: seq}).Error Updates(&pds.PDS{Cursor: seq}).Error
if err != nil { if err != nil {
return fmt.Errorf("updating Cursor: %w", err) return fmt.Errorf("updating Cursor: %w", err)
@ -271,7 +271,7 @@ func (c *Consumer) processMessage(ctx context.Context, typ string, r io.Reader,
if payload.TooBig { if payload.TooBig {
// Just trigger a re-index by resetting rev. // Just trigger a re-index by resetting rev.
err := c.db.Model(r).Where(&repo.Repo{Model: gorm.Model{ID: repoInfo.ID}}). err := c.db.Model(r).Where(&repo.Repo{ID: repoInfo.ID}).
Updates(&repo.Repo{ Updates(&repo.Repo{
FirstCursorSinceReset: c.remote.FirstCursorSinceReset, FirstCursorSinceReset: c.remote.FirstCursorSinceReset,
FirstRevSinceReset: payload.Rev, FirstRevSinceReset: payload.Rev,
@ -282,7 +282,7 @@ func (c *Consumer) processMessage(ctx context.Context, typ string, r io.Reader,
} }
if repoInfo.FirstCursorSinceReset != c.remote.FirstCursorSinceReset { if repoInfo.FirstCursorSinceReset != c.remote.FirstCursorSinceReset {
err := c.db.Model(r).Where(&repo.Repo{Model: gorm.Model{ID: repoInfo.ID}}). err := c.db.Model(r).Where(&repo.Repo{ID: repoInfo.ID}).
Updates(&repo.Repo{ Updates(&repo.Repo{
FirstCursorSinceReset: c.remote.FirstCursorSinceReset, FirstCursorSinceReset: c.remote.FirstCursorSinceReset,
FirstRevSinceReset: payload.Rev, FirstRevSinceReset: payload.Rev,

View File

@ -117,7 +117,7 @@ func (p *WorkerPool) worker(ctx context.Context, signal chan struct{}) {
} }
updates.LastIndexAttempt = time.Now() updates.LastIndexAttempt = time.Now()
err := p.db.Model(&repo.Repo{}). err := p.db.Model(&repo.Repo{}).
Where(&repo.Repo{Model: gorm.Model{ID: work.Repo.ID}}). Where(&repo.Repo{ID: work.Repo.ID}).
Updates(updates).Error Updates(updates).Error
if err != nil { if err != nil {
log.Error().Err(err).Msgf("Failed to update repo info for %q: %s", work.Repo.DID, err) log.Error().Err(err).Msgf("Failed to update repo info for %q: %s", work.Repo.DID, err)
@ -216,7 +216,7 @@ retry:
} }
} }
err = p.db.Model(&repo.Repo{}).Where(&repo.Repo{Model: gorm.Model{ID: work.Repo.ID}}). err = p.db.Model(&repo.Repo{}).Where(&repo.Repo{ID: work.Repo.ID}).
Updates(&repo.Repo{LastIndexedRev: newRev}).Error Updates(&repo.Repo{LastIndexedRev: newRev}).Error
if err != nil { if err != nil {
return fmt.Errorf("updating repo rev: %w", err) return fmt.Errorf("updating repo rev: %w", err)

View File

@ -4,10 +4,14 @@ import (
"time" "time"
"gorm.io/gorm" "gorm.io/gorm"
"github.com/uabluerail/indexer/models"
) )
type PDS struct { type PDS struct {
gorm.Model ID models.ID `gorm:"primarykey"`
CreatedAt time.Time
UpdatedAt time.Time
Host string `gorm:"uniqueIndex"` Host string `gorm:"uniqueIndex"`
Cursor int64 Cursor int64
FirstCursorSinceReset int64 FirstCursorSinceReset int64

View File

@ -16,7 +16,9 @@ import (
) )
type Repo struct { type Repo struct {
gorm.Model ID models.ID `gorm:"primarykey"`
CreatedAt time.Time
UpdatedAt time.Time
PDS models.ID `gorm:"index:rev_state_index,priority:2;index:was_indexed,priority:2"` PDS models.ID `gorm:"index:rev_state_index,priority:2;index:was_indexed,priority:2"`
DID string `gorm:"uniqueIndex;column:did"` DID string `gorm:"uniqueIndex;column:did"`
LastIndexedRev string `gorm:"index:rev_state_index,expression:(last_indexed_rev < first_rev_since_reset),priority:1;index:was_indexed,expression:(last_indexed_rev is null OR last_indexed_rev = ''),priority:1"` LastIndexedRev string `gorm:"index:rev_state_index,expression:(last_indexed_rev < first_rev_since_reset),priority:1;index:was_indexed,expression:(last_indexed_rev is null OR last_indexed_rev = ''),priority:1"`
@ -28,7 +30,9 @@ type Repo struct {
} }
type Record struct { type Record struct {
gorm.Model ID models.ID `gorm:"primarykey"`
CreatedAt time.Time
UpdatedAt time.Time
Repo models.ID `gorm:"index:idx_repo_record_key,unique,priority:1;not null"` Repo models.ID `gorm:"index:idx_repo_record_key,unique,priority:1;not null"`
Collection string `gorm:"index:idx_repo_record_key,unique,priority:2;not null"` Collection string `gorm:"index:idx_repo_record_key,unique,priority:2;not null"`
Rkey string `gorm:"index:idx_repo_record_key,unique,priority:3"` Rkey string `gorm:"index:idx_repo_record_key,unique,priority:3"`