SHAFI commited on
Commit ·
4dc7fb5
1
Parent(s): 998e591
fixed magzines, articles routing issue
Browse files- debug_collections.py +39 -0
- inspect_magazine.py +32 -0
- simulate_backend_request.py +46 -0
- verify_fix.py +34 -0
debug_collections.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import warnings
|
| 3 |
+
# Filter warnings
|
| 4 |
+
warnings.filterwarnings('ignore')
|
| 5 |
+
|
| 6 |
+
from app.services.appwrite_db import get_appwrite_db
|
| 7 |
+
from app.config import settings
|
| 8 |
+
from appwrite.query import Query
|
| 9 |
+
|
| 10 |
+
async def check_counts():
|
| 11 |
+
db = get_appwrite_db()
|
| 12 |
+
if not db.initialized:
|
| 13 |
+
print("DB not initialized")
|
| 14 |
+
return
|
| 15 |
+
|
| 16 |
+
print("\n" + "="*50)
|
| 17 |
+
print("DEBUG: MAGAZINE COLLECTION COUNTS")
|
| 18 |
+
print("="*50)
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
main_mag = await db.tablesDB.list_rows(
|
| 22 |
+
database_id=settings.APPWRITE_DATABASE_ID,
|
| 23 |
+
collection_id=settings.APPWRITE_COLLECTION_ID,
|
| 24 |
+
queries=[Query.equal('category', 'magazines'), Query.limit(1)]
|
| 25 |
+
)
|
| 26 |
+
ded_mag = await db.tablesDB.list_rows(
|
| 27 |
+
database_id=settings.APPWRITE_DATABASE_ID,
|
| 28 |
+
collection_id=settings.APPWRITE_MAGAZINE_COLLECTION_ID,
|
| 29 |
+
queries=[Query.limit(1)]
|
| 30 |
+
)
|
| 31 |
+
print(f"Magazines (Main Collection): {main_mag['total']}")
|
| 32 |
+
print(f"Magazines (Dedicated Collection): {ded_mag['total']}")
|
| 33 |
+
except Exception as e:
|
| 34 |
+
print(f"Error checking magazines: {e}")
|
| 35 |
+
|
| 36 |
+
print("="*50 + "\n")
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
asyncio.run(check_counts())
|
inspect_magazine.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import warnings
|
| 3 |
+
warnings.filterwarnings('ignore')
|
| 4 |
+
|
| 5 |
+
from app.services.appwrite_db import get_appwrite_db
|
| 6 |
+
from app.config import settings
|
| 7 |
+
from appwrite.query import Query
|
| 8 |
+
|
| 9 |
+
async def inspect():
|
| 10 |
+
db = get_appwrite_db()
|
| 11 |
+
if not db.initialized:
|
| 12 |
+
print("DB not initialized")
|
| 13 |
+
return
|
| 14 |
+
|
| 15 |
+
print("Fetching one document from Dedicated Magazine Collection...")
|
| 16 |
+
try:
|
| 17 |
+
res = await db.tablesDB.list_rows(
|
| 18 |
+
database_id=settings.APPWRITE_DATABASE_ID,
|
| 19 |
+
collection_id=settings.APPWRITE_MAGAZINE_COLLECTION_ID,
|
| 20 |
+
queries=[Query.limit(1)]
|
| 21 |
+
)
|
| 22 |
+
if res['documents']:
|
| 23 |
+
doc = res['documents'][0]
|
| 24 |
+
print(f"CATEGORY_VALUE: '{doc.get('category')}'")
|
| 25 |
+
print(f"PUBLISHED_AT: '{doc.get('published_at')}'")
|
| 26 |
+
else:
|
| 27 |
+
print("No documents found.")
|
| 28 |
+
except Exception as e:
|
| 29 |
+
print(f"Error: {e}")
|
| 30 |
+
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
asyncio.run(inspect())
|
simulate_backend_request.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import warnings
|
| 3 |
+
warnings.filterwarnings('ignore')
|
| 4 |
+
|
| 5 |
+
from app.services.appwrite_db import get_appwrite_db
|
| 6 |
+
from app.config import settings
|
| 7 |
+
from appwrite.query import Query
|
| 8 |
+
|
| 9 |
+
async def simulate():
|
| 10 |
+
db = get_appwrite_db()
|
| 11 |
+
|
| 12 |
+
category = 'magazines'
|
| 13 |
+
queries = [
|
| 14 |
+
Query.equal('category', category),
|
| 15 |
+
Query.order_desc('published_at'),
|
| 16 |
+
Query.limit(21)
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
# Needs to match what news.py receives/sends
|
| 20 |
+
|
| 21 |
+
print(f"Simulating request for category: {category}")
|
| 22 |
+
|
| 23 |
+
# 1. Check strict routing
|
| 24 |
+
target_id = db.get_collection_id(category)
|
| 25 |
+
print(f"Target Collection ID: {target_id} (Expected for strict: {settings.APPWRITE_MAGAZINE_COLLECTION_ID})")
|
| 26 |
+
|
| 27 |
+
if target_id == settings.APPWRITE_MAGAZINE_COLLECTION_ID:
|
| 28 |
+
print("Strict routing IS active (if you reverted it in code)")
|
| 29 |
+
else:
|
| 30 |
+
print("Strict routing IS NOT active (using main)")
|
| 31 |
+
|
| 32 |
+
# 2. Execute Query
|
| 33 |
+
try:
|
| 34 |
+
articles = await db.get_articles_with_queries(queries, category=category)
|
| 35 |
+
print(f"COUNT_ARTICLES: {len(articles)}")
|
| 36 |
+
except Exception as e:
|
| 37 |
+
print(f"ERROR: {e}")
|
| 38 |
+
|
| 39 |
+
'''
|
| 40 |
+
NOTE: You need to revert `appwrite_db.py` change
|
| 41 |
+
BEFORE running this to test strict routing!
|
| 42 |
+
Currently it should use MAIN collection and likely return 0.
|
| 43 |
+
'''
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
asyncio.run(simulate())
|
verify_fix.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from app.services.appwrite_db import AppwriteDatabase
|
| 2 |
+
from app.config import settings
|
| 3 |
+
|
| 4 |
+
def verify_routing():
|
| 5 |
+
db = AppwriteDatabase()
|
| 6 |
+
|
| 7 |
+
# 1. Verify Magazines Routing
|
| 8 |
+
mag_id = db.get_collection_id('magazines')
|
| 9 |
+
expected_mag_id = settings.APPWRITE_COLLECTION_ID
|
| 10 |
+
|
| 11 |
+
print(f"Magazines Collection ID: {mag_id}")
|
| 12 |
+
print(f"Expected (Main): {expected_mag_id}")
|
| 13 |
+
|
| 14 |
+
if mag_id == expected_mag_id:
|
| 15 |
+
print("✅ Magazines routing CORRECT (Using Main DB)")
|
| 16 |
+
else:
|
| 17 |
+
print("❌ Magazines routing INCORRECT (Still using dedicated DB)")
|
| 18 |
+
|
| 19 |
+
print("-" * 30)
|
| 20 |
+
|
| 21 |
+
# 2. Verify Medium Routing
|
| 22 |
+
med_id = db.get_collection_id('medium-article')
|
| 23 |
+
expected_med_id = settings.APPWRITE_MEDIUM_COLLECTION_ID
|
| 24 |
+
|
| 25 |
+
print(f"Medium Collection ID: {med_id}")
|
| 26 |
+
print(f"Expected (Dedicated): {expected_med_id}")
|
| 27 |
+
|
| 28 |
+
if med_id == expected_med_id:
|
| 29 |
+
print("✅ Medium routing CORRECT (Using Dedicated DB)")
|
| 30 |
+
else:
|
| 31 |
+
print("❌ Medium routing INCORRECT")
|
| 32 |
+
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
verify_routing()
|