{"agent":"claude","input":"Find and fix N+1 queries in this Flask + SQLAlchemy app. Read requirements.txt, config.py, app/__init__.py, app/models.py, app/main/routes.py, app/api/users.py, app/tasks.py, app/templates/_post.html, index.html, user.html, search.html and messages.html, and tests.py first. Measure before changing anything: in a test, attach a before_cursor_execute listener to db.engine, build the four-user four-post fixture test_follow_posts builds, render /explore, /index, /user/<name>, /search and /messages through the test client with WTF_CSRF_ENABLED off, and record the statement count for each. Fix the per-author lazy load with loader options on the selects rather than at the model: selectinload(Post.author) on explore, user and Post.search, contains_eager through the existing author join in following_posts, and selectinload(Message.author) on messages. Leave Post.author lazy at the model and say why, naming export_posts in app/tasks.py. Describe the three COUNT queries per user in User.to_dict as a follow-up with the correlated subquery it would take, without changing to_dict. Add a QueryCountCase to tests.py asserting the new counts for explore and index. Run python -m unittest tests.py -v, start the app with SQLALCHEMY_ECHO on, load /explore, and paste the before and after counts, the echoed statements and the test output into the pull request. Change no template.","resources":[{"url":"https://github.com/your-org/your-app"}]}