Minor multi-user timeline optimization

This commit is contained in:
Zed 2020-04-29 15:06:15 +02:00
parent 326776fde7
commit feb939d918

View file

@ -48,7 +48,7 @@ proc getReplyQuery*(name: string): Query =
fromUser: @[name] fromUser: @[name]
) )
proc genQueryParam*(query: Query): string = proc genQueryParam*(query: Query; rewriteReplies=true): string =
var filters: seq[string] var filters: seq[string]
var param: string var param: string
let userSearch = query.fromUser.len > 0 let userSearch = query.fromUser.len > 0
@ -56,13 +56,9 @@ proc genQueryParam*(query: Query): string =
if query.kind == users: if query.kind == users:
return query.text return query.text
# improve no-replies result only when searching for less than 7
# otherwise multi-timeline limit goes down to 8 users
let rewriteReplies = "replies" in query.excludes and query.fromUser.len < 7
for i, user in query.fromUser: for i, user in query.fromUser:
if rewriteReplies: if rewriteReplies:
param &= &"(from:{user} AND (to:{user} OR -filter:replies)) " param &= &"(from:{user}(to:{user} OR -filter:replies)) "
else: else:
param &= &"from:{user} " param &= &"from:{user} "
@ -87,6 +83,9 @@ proc genQueryParam*(query: Query): string =
if query.text.len > 0: if query.text.len > 0:
result &= " " & query.text result &= " " & query.text
if userSearch and rewriteReplies and result.len >= 500:
return genQueryParam(query, rewriteReplies=false)
proc genQueryUrl*(query: Query): string = proc genQueryUrl*(query: Query): string =
if query.kind notin {tweets, users}: return if query.kind notin {tweets, users}: return