limit comments per user
This commit is contained in:
@@ -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
@@ -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/
|
||||
Reference in New Issue
Block a user