A community based topic aggregation platform built on atproto

fix(db): fix pointer reuse bug in ListBlockedCommunities

Critical bug fix: The loop variable 'block' was being reused for each
iteration, causing all elements in the returned slice to point to the
same memory location. This resulted in the last row being repeated for
every element when callers read the list.

Fixed by allocating a new block pointer for each iteration:
- Before: var block communities.CommunityBlock (reused)
- After: block := &communities.CommunityBlock{} (new allocation)

Also replaced fmt.Printf with log.Printf for consistency with project
logging standards.

Addresses: P1 review comment - pointer reuse in list operation

Changed files
+5 -3
internal
+5 -3
internal/db/postgres/community_repo_blocks.go
···
"context"
"database/sql"
"fmt"
+
"log"
)
// BlockCommunity creates a new block record (idempotent)
···
defer func() {
if closeErr := rows.Close(); closeErr != nil {
// Log error but don't override the main error
-
fmt.Printf("Failed to close rows: %v\n", closeErr)
+
log.Printf("Failed to close rows: %v", closeErr)
}
}()
var blocks []*communities.CommunityBlock
for rows.Next() {
-
var block communities.CommunityBlock
+
// Allocate a new block for each iteration to avoid pointer reuse bug
+
block := &communities.CommunityBlock{}
err = rows.Scan(
&block.ID,
···
return nil, fmt.Errorf("failed to scan block: %w", err)
}
-
blocks = append(blocks, &block)
+
blocks = append(blocks, block)
}
if err = rows.Err(); err != nil {