fix: COALESCE all bare p.duration_ms to prevent NULL scan crash on focus-context and other queries

This commit is contained in:
Patrick Britton 2026-02-07 16:29:35 -06:00
parent 10c48f1fd7
commit c83317c29c

View file

@ -83,7 +83,7 @@ func (r *PostRepository) CreatePost(ctx context.Context, post *models.Post) erro
func (r *PostRepository) GetRandomSponsoredPost(ctx context.Context, userID string) (*models.Post, error) { func (r *PostRepository) GetRandomSponsoredPost(ctx context.Context, userID string) (*models.Post, error) {
query := ` query := `
SELECT SELECT
p.id, p.author_id, p.category_id, p.body, COALESCE(p.image_url, ''), COALESCE(p.video_url, ''), COALESCE(p.thumbnail_url, ''), p.duration_ms, COALESCE(p.tags, ARRAY[]::text[]), p.created_at, p.id, p.author_id, p.category_id, p.body, COALESCE(p.image_url, ''), COALESCE(p.video_url, ''), COALESCE(p.thumbnail_url, ''), COALESCE(p.duration_ms, 0), COALESCE(p.tags, ARRAY[]::text[]), p.created_at,
pr.handle as author_handle, pr.display_name as author_display_name, COALESCE(pr.avatar_url, '') as author_avatar_url, pr.handle as author_handle, pr.display_name as author_display_name, COALESCE(pr.avatar_url, '') as author_avatar_url,
COALESCE(m.like_count, 0) as like_count, COALESCE(m.comment_count, 0) as comment_count, COALESCE(m.like_count, 0) as like_count, COALESCE(m.comment_count, 0) as comment_count,
FALSE as is_liked, FALSE as is_liked,
@ -295,7 +295,7 @@ func (r *PostRepository) GetPostByID(ctx context.Context, postID string, userID
ELSE '' ELSE ''
END AS resolved_video_url, END AS resolved_video_url,
COALESCE(NULLIF(p.thumbnail_url, ''), p.image_url, '') AS resolved_thumbnail_url, COALESCE(NULLIF(p.thumbnail_url, ''), p.image_url, '') AS resolved_thumbnail_url,
p.duration_ms, COALESCE(p.duration_ms, 0),
COALESCE(p.tags, ARRAY[]::text[]), COALESCE(p.tags, ARRAY[]::text[]),
p.created_at, p.created_at,
p.chain_parent_id, p.chain_parent_id,
@ -972,7 +972,7 @@ func (r *PostRepository) GetPostFocusContext(ctx context.Context, postID string,
ELSE '' ELSE ''
END AS resolved_video_url, END AS resolved_video_url,
COALESCE(NULLIF(p.thumbnail_url, ''), p.image_url, '') AS resolved_thumbnail_url, COALESCE(NULLIF(p.thumbnail_url, ''), p.image_url, '') AS resolved_thumbnail_url,
p.duration_ms, COALESCE(p.duration_ms, 0),
COALESCE(p.tags, ARRAY[]::text[]), COALESCE(p.tags, ARRAY[]::text[]),
p.created_at, p.created_at,
pr.handle as author_handle, pr.display_name as author_display_name, COALESCE(pr.avatar_url, '') as author_avatar_url, pr.handle as author_handle, pr.display_name as author_display_name, COALESCE(pr.avatar_url, '') as author_avatar_url,
@ -1290,7 +1290,7 @@ func (r *PostRepository) GetPopularPublicPosts(ctx context.Context, viewerID str
ELSE '' ELSE ''
END AS resolved_video_url, END AS resolved_video_url,
COALESCE(NULLIF(p.thumbnail_url, ''), p.image_url, '') AS resolved_thumbnail_url, COALESCE(NULLIF(p.thumbnail_url, ''), p.image_url, '') AS resolved_thumbnail_url,
p.duration_ms, COALESCE(p.duration_ms, 0),
COALESCE(p.tags, ARRAY[]::text[]), COALESCE(p.tags, ARRAY[]::text[]),
p.created_at, p.created_at,
pr.handle as author_handle, pr.display_name as author_display_name, COALESCE(pr.avatar_url, '') as author_avatar_url, pr.handle as author_handle, pr.display_name as author_display_name, COALESCE(pr.avatar_url, '') as author_avatar_url,