From a602e02c9ccbf4b6c94f9d0af6a8b4b005273f81 Mon Sep 17 00:00:00 2001 From: Asaf Gartner Date: Thu, 27 Jun 2024 23:13:22 +0300 Subject: [PATCH] Fixed timeline query for user+project combo --- src/hmndata/timeline_helper.go | 46 ++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/hmndata/timeline_helper.go b/src/hmndata/timeline_helper.go index 84dfe6f1..719b3462 100644 --- a/src/hmndata/timeline_helper.go +++ b/src/hmndata/timeline_helper.go @@ -129,10 +129,12 @@ func FetchTimeline( WHERE TRUE `, ) - if len(q.ProjectIDs) > 0 { - qb.Add( - ` - AND ( + if len(q.ProjectIDs)+len(q.OwnerIDs) > 0 { + qb.Add(`AND (`) + if len(q.ProjectIDs) > 0 { + qb.Add( + ` + ( SELECT count(*) FROM snippet_project WHERE @@ -140,9 +142,19 @@ func FetchTimeline( AND snippet_project.project_id = ANY($?) ) > 0 - `, - q.ProjectIDs, - ) + `, + q.ProjectIDs, + ) + } else { + qb.Add("FALSE") + } + qb.Add(" OR ") + if len(q.OwnerIDs) > 0 { + qb.Add(`owner_id = ANY($?)`, q.OwnerIDs) + } else { + qb.Add("FALSE") + } + qb.Add(`)`) } qb.Add( ` @@ -169,8 +181,20 @@ func FetchTimeline( WHERE post.deleted = false AND thread.deleted = false `, ) - if len(q.ProjectIDs) > 0 { - qb.Add(`AND post.project_id = ANY($?)`, q.ProjectIDs) + if len(q.OwnerIDs)+len(q.ProjectIDs) > 0 { + qb.Add(`AND (`) + if len(q.ProjectIDs) > 0 { + qb.Add(`post.project_id = ANY($?)`, q.ProjectIDs) + } else { + qb.Add("FALSE") + } + qb.Add(" OR ") + if len(q.OwnerIDs) > 0 { + qb.Add(`post.author_id = ANY($?)`, q.OwnerIDs) + } else { + qb.Add("FALSE") + } + qb.Add(`)`) } qb.Add( ` @@ -192,10 +216,6 @@ func FetchTimeline( `, ) - if len(q.OwnerIDs) > 0 { - qb.Add(`AND owner_id = ANY($?)`, q.OwnerIDs) - } - if currentUser == nil { qb.Add( `AND owner.status = $? -- snippet owner is Approved`,