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