graph2: Added importLog query and associated models and repository functions.
the build was successful

This commit is contained in:
2018-12-01 16:52:06 +01:00
parent 2a91b6f9bc
commit a58535fcb9
11 changed files with 282 additions and 6 deletions
+34
View File
@@ -0,0 +1,34 @@
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
}