A bit of query optimization
parent
63a767d890
commit
8561d90caf
|
@ -106,12 +106,11 @@ func (s *Scheduler) fillQueue(ctx context.Context) error {
|
|||
for _, remote := range remotes {
|
||||
repos := []repo.Repo{}
|
||||
|
||||
err := s.db.Model(&repos).
|
||||
Where(`pds = ? AND (
|
||||
last_indexed_rev is null OR last_indexed_rev = ''
|
||||
OR (first_rev_since_reset is not null AND first_rev_since_reset <> '' AND last_indexed_rev < first_rev_since_reset))`,
|
||||
remote.ID).
|
||||
Limit(perPDSLimit).Find(&repos).Error
|
||||
err := s.db.Raw(`SELECT * FROM "repos" WHERE pds = ? AND (last_indexed_rev is null OR last_indexed_rev = '')
|
||||
UNION
|
||||
SELECT * FROM "repos" WHERE pds = ? AND (first_rev_since_reset is not null AND first_rev_since_reset <> '' AND last_indexed_rev < first_rev_since_reset) LIMIT ?`,
|
||||
remote.ID, remote.ID, perPDSLimit).
|
||||
Scan(&repos).Error
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("querying DB: %w", err)
|
||||
|
|
|
@ -17,9 +17,9 @@ import (
|
|||
|
||||
type Repo struct {
|
||||
gorm.Model
|
||||
PDS models.ID `gorm:"index:rev_state_index,priority:2"`
|
||||
PDS models.ID `gorm:"index:rev_state_index,priority:2;index:was_indexed,priority:2"`
|
||||
DID string `gorm:"uniqueIndex;column:did"`
|
||||
LastIndexedRev string `gorm:"index:rev_state_index,expression:(last_indexed_rev < first_rev_since_reset),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"`
|
||||
FirstRevSinceReset string
|
||||
FirstCursorSinceReset int64
|
||||
TombstonedAt time.Time
|
||||
|
|
Loading…
Reference in New Issue