Skip to content

Conversation

Copy link

Copilot AI commented Nov 24, 2025

Adds endpoint to retrieve safe-for-work posts by excluding holes with NSFW tags.

Changes

  • Route: GET /api/holes/_sfw returns holes without NSFW tags
  • Query: Uses LEFT JOIN on hole_tags with subquery for NSFW tag IDs, filtering on NULL matches
  • Test: Verifies NSFW tagged holes are excluded, leverages Tag's BeforeCreate hook (tags starting with * auto-set nsfw=true)

Implementation

// Exclude holes with NSFW tags using optimized LEFT JOIN
nsfwTagIDs := DB.Table("tag").Select("id").Where("nsfw = ?", true)
querySet = querySet.
    Joins("LEFT JOIN hole_tags ON hole.id = hole_tags.hole_id AND hole_tags.tag_id IN (?)", nsfwTagIDs).
    Where("hole_tags.hole_id IS NULL").
    Group("hole.id")

Pattern mirrors ListGoodHoles endpoint. LEFT JOIN approach scales better than NOT IN subquery for large datasets.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature Request] 增加一个新接口,获取safe for work的帖子</issue_title>
<issue_description>你的功能需求和某个bug有关吗?
[否]

你想要什么样的功能?
Get /divisions/:id/holes/_sfw
实现上,可能要join tag表,找出nsfw的tag然后处理

</issue_description>

<agent_instructions>Keep modifications minimal.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add new API endpoint to get safe for work posts Add /holes/_sfw endpoint to filter NSFW tagged posts Nov 24, 2025
Copilot AI requested a review from KYLN24 November 24, 2025 06:38
@KYLN24 KYLN24 requested review from Copilot and ppolariss and removed request for KYLN24 November 24, 2025 09:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new endpoint /api/holes/_sfw that returns holes without NSFW tags, enabling users to filter out not-safe-for-work content. The implementation follows established patterns in the codebase, particularly mirroring the ListGoodHoles endpoint structure.

Key Changes

  • New GET endpoint at /holes/_sfw with query parameter support for pagination and ordering
  • SQL query uses LEFT JOIN with subquery to efficiently filter out holes with NSFW tags
  • Test coverage validates that NSFW-tagged holes are properly excluded

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
apis/hole/routes.go Registers the new /holes/_sfw route endpoint
apis/hole/apis.go Implements ListSfwHoles handler with LEFT JOIN query to exclude NSFW-tagged holes
tests/hole_test.go Adds test case that creates NSFW and safe holes, verifies NSFW filtering works correctly

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] 增加一个新接口,获取safe for work的帖子

2 participants