Comments Feature - #7
Conversation
Feat: DetailUserRead
Feat: Comments endpoint + comments response + comments replies response
Upd: Interface for CommentRepository Upd: comments endpoint Upd: DetailUserRead response class for endpoints
Pull Request Review: Comments FeatureOverviewThis PR implements pagination for comments and refactors the comments feature. Overall good work on adding pagination support! Here are my findings: 🐛 Critical Bugs1. Debug Print Statement Left in Production CodeLocation: parent_comment = await self.comment_repo.get_by_id(create_data.parent_id)
print(parent_comment.id) # ❌ Debug statementIssue: Debug print statement should be removed before merging. 2. Incorrect Field Default in BaseMark SchemaLocation: start_at: Annotated[
datetime,
Field(default_factory=datetime.now, description="Current date"),
]Issue: While changing from 3. Missing Unique Constraint Check in PaginationLocation: comments = await self.adapter.execute_query(stmt, unique=True)Issue: Using
|
Pull Request Review: Comments FeatureOverviewThis PR introduces a comprehensive comments system for marks with pagination, nested replies, and comment statistics. The implementation shows solid architectural patterns with repository, service, and schema layers, though there are several areas that need attention. Critical Issues1. Data Integrity Risk - Soft Delete Query InconsistencyLocation: realtimemap/modules/mark_comment/repository.py:98 The get_comments method filters comments with Comment.is_deleted == False in the main query but uses .count() without the same filter. This could lead to pagination displaying incorrect totals if soft-deleted comments exist. Recommendation: Ensure consistent filtering of is_deleted == False across all queries and counts. 2. Inconsistent Default Field UsageLocation: realtimemap/modules/mark/schemas/base.py:55 The change from Field(default=datetime.now()) to Field(default_factory=datetime.now) is correct. Calling datetime.now() at module import time would create a single timestamp for all instances. Good fix in this PR! Security Concerns3. Missing Authorization ChecksLocation: realtimemap/api/v1/mark/comment_view.py:42-57 The create_comment_endpoint checks if the mark exists but does not verify:
Recommendation: Add authorization checks in the service layer to validate business rules before allowing comment creation. 4. Cache Namespace Collision RiskLocation: realtimemap/api/v1/mark/comment_view.py:65,82 Both endpoints use the same cache namespace mark-comments. Verify that fastapi-cache2 includes all function parameters in the cache key to prevent collisions. Code Quality Issues5. N+1 Query PotentialLocation: realtimemap/modules/mark_comment/repository.py:73-118 The manual filtering of replies to only show the first one happens in Python. This loads ALL replies from the database but only uses one. For comments with many replies, this is inefficient. Recommendation: Modify the query to use a window function or subquery to fetch only the first reply per comment at the database level. 6. Commented-Out Code Should Be RemovedLocation: realtimemap/api/v1/mark/comment_view.py:92-101 Commented-out code should be removed. If this feature is planned for the future, track it with a TODO comment with a ticket reference, or remove it entirely and rely on git history. 7. Empty Hook Methods Are MisleadingLocation: realtimemap/modules/mark_comment/service.py:74-91 These methods are called but do nothing. If they are meant for future extension or for subclasses to override, document this in the class docstring or remove them to reduce complexity. Positive AspectsWell-Structured PaginationThe custom PaginationResponse and PaginationParams classes are well-designed with clear separation of concerns, computed fields for has_next, has_prev, and total_pages, type-safe with generics, and reusable across the application. Good Use of SlotsUsing slots in the service class is excellent for memory efficiency. Proper Type HintsThe code uses comprehensive type hints with TYPE_CHECKING guards to avoid circular imports. Database Optimization
Removed Dead CodeRemoving the old MarkComment model and cleaning up debug logs shows good housekeeping. Missing Elements8. No Tests for New FunctionalityThere are no tests added for comment creation with parent comments, pagination logic, reply fetching, or nesting level validation. 9. Missing API DocumentationThe FastAPI endpoints lack detailed OpenAPI documentation with summaries and descriptions. 10. No Migration File VisibleThe PR removes the MarkComment model but does not show the corresponding Alembic migration. Performance Considerations11. Cache Expiration Too Short?Comments are cached for only 60 seconds. Consider whether comments are updated frequently enough to warrant such a short TTL. 12. Potential Memory Issue with Large Comment ThreadsIf a comment has thousands of replies, the current implementation loads them all even though only the first reply is returned. Summary & RecommendationsMust Fix Before Merge:
Should Fix Soon:
Overall AssessmentCode Quality: 7/10 This is a solid foundation for a comments system with good architectural patterns. The main concerns are the missing tests, the N+1 query issue, and the lack of authorization checks. Once these are addressed, this will be ready to merge. Great work on the pagination implementation and the clean separation of concerns! |
No description provided.