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 {
|
for _, remote := range remotes {
|
||||||
repos := []repo.Repo{}
|
repos := []repo.Repo{}
|
||||||
|
|
||||||
err := s.db.Model(&repos).
|
err := s.db.Raw(`SELECT * FROM "repos" WHERE pds = ? AND (last_indexed_rev is null OR last_indexed_rev = '')
|
||||||
Where(`pds = ? AND (
|
UNION
|
||||||
last_indexed_rev is null OR last_indexed_rev = ''
|
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 ?`,
|
||||||
OR (first_rev_since_reset is not null AND first_rev_since_reset <> '' AND last_indexed_rev < first_rev_since_reset))`,
|
remote.ID, remote.ID, perPDSLimit).
|
||||||
remote.ID).
|
Scan(&repos).Error
|
||||||
Limit(perPDSLimit).Find(&repos).Error
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("querying DB: %w", err)
|
return fmt.Errorf("querying DB: %w", err)
|
||||||
|
|
|
@ -17,9 +17,9 @@ import (
|
||||||
|
|
||||||
type Repo struct {
|
type Repo struct {
|
||||||
gorm.Model
|
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"`
|
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
|
FirstRevSinceReset string
|
||||||
FirstCursorSinceReset int64
|
FirstCursorSinceReset int64
|
||||||
TombstonedAt time.Time
|
TombstonedAt time.Time
|
||||||
|
|
Loading…
Reference in New Issue