@@ -225,6 +225,11 @@ def get_personal_feed_posts(
225225 Get workout posts from users that the specified user follows (personal feed).
226226 Includes privacy filtering: private posts only visible if mutual follow.
227227 """
228+ # Early check: if no WorkoutPost records exist, return empty result immediately
229+ total_posts_check = session .exec (select (func .count ()).select_from (WorkoutPost )).one ()
230+ if total_posts_check == 0 :
231+ return [], 0
232+
228233 # Get IDs of users that the current user follows
229234 following_statement = (
230235 select (UserFollow .followed_id )
@@ -235,16 +240,18 @@ def get_personal_feed_posts(
235240 # Include the user's own posts in the feed
236241 following_ids .append (user_id )
237242
243+ # If no one to follow (including self), return empty
244+ if not following_ids :
245+ return [], 0
246+
238247 # Build privacy filter conditions
239248 privacy_conditions = []
240249
241250 for followed_id in following_ids :
242251 if followed_id == user_id :
243252 # User's own posts - always visible
244253 privacy_conditions .append (
245- and_ (
246- WorkoutPost .user_id == user_id
247- )
254+ WorkoutPost .user_id == user_id
248255 )
249256 else :
250257 # Posts from followed users
@@ -297,6 +304,11 @@ def get_public_feed_posts(
297304 """
298305 Get all public workout posts from all users (discovery feed).
299306 """
307+ # Early check: if no WorkoutPost records exist, return empty result immediately
308+ total_posts_check = session .exec (select (func .count ()).select_from (WorkoutPost )).one ()
309+ if total_posts_check == 0 :
310+ return [], 0
311+
300312 # Count all public posts
301313 count_statement = (
302314 select (func .count ())
0 commit comments