Skip to content

Commit

Permalink
fix: Reindex after rescraping scenes (xbapps#1572)
Browse files Browse the repository at this point in the history
  • Loading branch information
toshski authored Jan 15, 2024
1 parent d074f7e commit 55111fe
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/tasks/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func sceneSliceAppender(collectedScenes *[]models.ScrapedScene, scenes <-chan mo
}
}

func sceneDBWriter(wg *sync.WaitGroup, i *uint64, scenes <-chan models.ScrapedScene) {
func sceneDBWriter(wg *sync.WaitGroup, i *uint64, scenes <-chan models.ScrapedScene, processedScenes *[]models.ScrapedScene, lock *sync.Mutex) {
defer wg.Done()

db, _ := models.GetDB()
Expand All @@ -164,6 +164,11 @@ func sceneDBWriter(wg *sync.WaitGroup, i *uint64, scenes <-chan models.ScrapedSc
} else {
models.SceneCreateUpdateFromExternal(db, scene)
}
// Add the processed scene to the list to re/index
lock.Lock()
*processedScenes = append(*processedScenes, scene)
lock.Unlock()

atomic.AddUint64(i, 1)
if os.Getenv("DEBUG") != "" {
log.Printf("Saved %v", scene.SceneID)
Expand Down Expand Up @@ -295,9 +300,12 @@ func Scrape(toScrape string, singleSceneURL string, singeScrapeAdditionalInfo st
collectedScenes := make(chan models.ScrapedScene, 250)
var sceneCount uint64

var processedScenes []models.ScrapedScene
var processedScenesLock sync.Mutex

var wg sync.WaitGroup
wg.Add(1)
go sceneDBWriter(&wg, &sceneCount, collectedScenes)
go sceneDBWriter(&wg, &sceneCount, collectedScenes, &processedScenes, &processedScenesLock)

// Start scraping
if e := runScrapers(knownScenes, toScrape, true, collectedScenes, singleSceneURL, singeScrapeAdditionalInfo); e != nil {
Expand Down Expand Up @@ -329,7 +337,7 @@ func Scrape(toScrape string, singleSceneURL string, singeScrapeAdditionalInfo st
tlog.Infof("Reapplying edits")
ReapplyEdits()

SearchIndex()
IndexScrapedScenes(&processedScenes)

tlog.Infof("Scraped %v new scenes in %s",
sceneCount,
Expand Down

0 comments on commit 55111fe

Please sign in to comment.