limit comments per user

This commit is contained in:
Umputun
2017-12-26 17:27:48 -06:00
parent 4f5635481d
commit b1c423e437
2 changed files with 9 additions and 1 deletions
+8
View File
@@ -24,6 +24,7 @@ const (
userBucketName = "users"
blocksBucketPrefix = "block-"
lastLimit = 1000
userLimit = 100
)
// NewBoltDB makes persistent boltdb-based store
@@ -440,6 +441,13 @@ func (b *BoltDB) GetForUser(locator Locator, userID string) (comments []Comment,
comments = append(comments, c)
}
}
// limit comment to recent up to userLimit. TODO: optimize to fetch in sorted order
sort.Slice(comments, func(i int, j int) bool { return comments[i].Timestamp.After(comments[j].Timestamp) })
if len(comments) > userLimit {
comments = comments[:userLimit]
}
return comments, err
}
+1 -1
View File
@@ -37,7 +37,7 @@ GET https://demo.remark42.com/api/v1/user
GET https://demo.remark42.com/api/v1/id/3665976683?url=https://radio-t.com/p/2017/12/16/podcast-576/
### get comment by user id
GET https://demo.remark42.com/api/v1/comments?user=grigorybakunov
GET https://demo.remark42.com/api/v1/comments?user=umputun
### get counts
GET https://demo.remark42.com/api/v1/count?url=https://radio-t.com/p/2017/12/16/podcast-576/