Investigate comments loading issue (Issue #4)
- Added debug logging to post_detail route to track comment loading - Created migration script for poll source fields (max_posts, fetch_comments, priority) - Migration adds default values to ensure comments are fetched The issue may be that existing poll sources in database dont have fetch_comments field. Migration needs to be run on server with database access. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
3
app.py
3
app.py
@@ -552,7 +552,8 @@ def post_detail(post_id):
|
|||||||
|
|
||||||
# Get comments from cache
|
# Get comments from cache
|
||||||
comments = cached_comments.get(post_id, [])
|
comments = cached_comments.get(post_id, [])
|
||||||
|
logger.info(f"Loading post {post_id}: found {len(comments)} comments")
|
||||||
|
|
||||||
# Sort comments by timestamp
|
# Sort comments by timestamp
|
||||||
comments.sort(key=lambda x: x.get('timestamp', 0))
|
comments.sort(key=lambda x: x.get('timestamp', 0))
|
||||||
|
|
||||||
|
|||||||
66
migrate_poll_source_fields.py
Normal file
66
migrate_poll_source_fields.py
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Database migration to add new polling configuration fields to poll_sources table.
|
||||||
|
Run this once to add the new columns: max_posts, fetch_comments, priority
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from app import app, db
|
||||||
|
|
||||||
|
def migrate():
|
||||||
|
"""Add polling configuration columns to poll_sources table"""
|
||||||
|
with app.app_context():
|
||||||
|
try:
|
||||||
|
# Check if columns already exist
|
||||||
|
from sqlalchemy import inspect
|
||||||
|
inspector = inspect(db.engine)
|
||||||
|
columns = [col['name'] for col in inspector.get_columns('poll_sources')]
|
||||||
|
|
||||||
|
if 'max_posts' in columns and 'fetch_comments' in columns and 'priority' in columns:
|
||||||
|
print("✓ Polling configuration columns already exist")
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Add the new columns using raw SQL
|
||||||
|
with db.engine.connect() as conn:
|
||||||
|
if 'max_posts' not in columns:
|
||||||
|
print("Adding max_posts column...")
|
||||||
|
conn.execute(db.text(
|
||||||
|
"ALTER TABLE poll_sources ADD COLUMN max_posts INTEGER NOT NULL DEFAULT 100"
|
||||||
|
))
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
if 'fetch_comments' not in columns:
|
||||||
|
print("Adding fetch_comments column...")
|
||||||
|
conn.execute(db.text(
|
||||||
|
"ALTER TABLE poll_sources ADD COLUMN fetch_comments BOOLEAN NOT NULL DEFAULT TRUE"
|
||||||
|
))
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
if 'priority' not in columns:
|
||||||
|
print("Adding priority column...")
|
||||||
|
conn.execute(db.text(
|
||||||
|
"ALTER TABLE poll_sources ADD COLUMN priority VARCHAR(20) NOT NULL DEFAULT 'medium'"
|
||||||
|
))
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
print("✓ Polling configuration columns added successfully")
|
||||||
|
print("\nUpdating existing poll sources with default values...")
|
||||||
|
|
||||||
|
# Update existing rows to have default values
|
||||||
|
with db.engine.connect() as conn:
|
||||||
|
result = conn.execute(db.text("UPDATE poll_sources SET fetch_comments = TRUE WHERE fetch_comments IS NULL"))
|
||||||
|
conn.commit()
|
||||||
|
print(f"✓ Updated {result.rowcount} rows with default fetch_comments=TRUE")
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"✗ Migration failed: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
return False
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print("Running poll source fields migration...")
|
||||||
|
success = migrate()
|
||||||
|
sys.exit(0 if success else 1)
|
||||||
Reference in New Issue
Block a user