fixed post relationships

This commit is contained in:
Ross Trottier 2024-07-19 10:50:59 -06:00
parent 60a8597b15
commit 1d6808d047

View File

@ -313,14 +313,14 @@ func createPost(postId int, migration MigratePosts, wpTagData []wordpress.TagDat
func updatePostRelationships(postResults []PostResult, migration MigratePosts) {
fmt.Println("Updating post relationships")
totalPostResults := len(postResults)
batchSize := 5
postResultWorkInput := make(chan PostResult)
doneChannel := make(chan bool)
defer close(doneChannel)
//Set up a wait group to wait for the input channel to close after execution
var wg sync.WaitGroup
wg.Add(1)
wg.Add(len(postResults))
wg.Add(totalPostResults + 1)
//Launch go routines that will read from the input channel,
//maxed out at the batch size
@ -330,9 +330,13 @@ func updatePostRelationships(postResults []PostResult, migration MigratePosts) {
select {
case <-doneChannel:
return
case result := <-postResultWorkInput:
case result, ok := <-postResultWorkInput:
if ok {
updatePostRelationship(result, migration)
wg.Done()
} else {
return
}
}
}
}()
@ -342,7 +346,7 @@ func updatePostRelationships(postResults []PostResult, migration MigratePosts) {
//as the workers take work from the channel. This will be blocked while
//any task is waiting to be picked up from the channel
go func() {
defer close(postResultWorkInput)
//defer close(postResultWorkInput)
for _, result := range postResults {
select {
@ -351,7 +355,6 @@ func updatePostRelationships(postResults []PostResult, migration MigratePosts) {
case postResultWorkInput <- result:
}
}
wg.Done()
}()