package posts import ( "git.aiterp.net/rpdata/api/internal/counter" "git.aiterp.net/rpdata/api/models" ) // AddMany adds multiple posts in on query. Each post gets a new ID and is associated with the log. func AddMany(log models.Log, posts []models.Post) ([]models.Post, error) { docs := make([]interface{}, len(posts)) mutex.RLock() defer mutex.RUnlock() startPosition, err := counter.NextMany("next_post_id", log.ShortID, len(posts)) if err != nil { return nil, err } for i, post := range posts { post.ID = generateID(post.Time) post.LogID = log.ShortID post.Position = startPosition + i docs[i] = post } err = collection.Insert(docs...) if err != nil { return nil, err } return posts, nil }