37 lines
696 B
Go
Raw Normal View History

2017-06-26 23:41:16 +02:00
package main
import (
2019-06-03 18:32:43 +09:00
"github.com/animenotifier/notify.moe/arn"
2017-06-26 23:41:16 +02:00
)
func main() {
2017-11-01 20:11:05 +01:00
defer arn.Node.Close()
2017-06-26 23:41:16 +02:00
2017-11-01 20:11:05 +01:00
// Get a stream of all posts
2017-06-26 23:41:16 +02:00
threadToPosts := make(map[string][]string)
// Iterate over the stream
2017-11-01 20:11:05 +01:00
for post := range arn.StreamPosts() {
2018-10-29 09:28:24 +09:00
if post.ParentType != "Thread" {
continue
}
_, found := threadToPosts[post.ParentID]
2017-06-26 23:41:16 +02:00
if !found {
2018-10-29 09:28:24 +09:00
threadToPosts[post.ParentID] = []string{post.ID}
2017-06-26 23:41:16 +02:00
} else {
2018-10-29 09:28:24 +09:00
threadToPosts[post.ParentID] = append(threadToPosts[post.ParentID], post.ID)
2017-06-26 23:41:16 +02:00
}
}
// Save new post ID lists
for threadID, posts := range threadToPosts {
thread, err := arn.GetThread(threadID)
arn.PanicOnError(err)
2018-10-29 09:28:24 +09:00
thread.PostIDs = posts
2017-11-01 20:11:05 +01:00
thread.Save()
2017-06-26 23:41:16 +02:00
}
}