|
@ -8,6 +8,7 @@ import ( |
|
|
// AddMany adds multiple posts in on query. Each post gets a new ID and is associated with the log.
|
|
|
// 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) { |
|
|
func AddMany(log models.Log, posts []models.Post) ([]models.Post, error) { |
|
|
docs := make([]interface{}, len(posts)) |
|
|
docs := make([]interface{}, len(posts)) |
|
|
|
|
|
copies := make([]models.Post, len(posts)) |
|
|
|
|
|
|
|
|
mutex.RLock() |
|
|
mutex.RLock() |
|
|
defer mutex.RUnlock() |
|
|
defer mutex.RUnlock() |
|
@ -23,6 +24,7 @@ func AddMany(log models.Log, posts []models.Post) ([]models.Post, error) { |
|
|
post.Position = startPosition + i |
|
|
post.Position = startPosition + i |
|
|
|
|
|
|
|
|
docs[i] = post |
|
|
docs[i] = post |
|
|
|
|
|
copies[i] = post |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
err = collection.Insert(docs...) |
|
|
err = collection.Insert(docs...) |
|
@ -30,5 +32,5 @@ func AddMany(log models.Log, posts []models.Post) ([]models.Post, error) { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return posts, nil |
|
|
|
|
|
|
|
|
return copies, nil |
|
|
} |
|
|
} |