c4-rdarr db updates
This commit is contained in:
@@ -0,0 +1,214 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script for comparing Radarr API vs Database performance
|
||||
Run this to validate the new database client functionality
|
||||
"""
|
||||
|
||||
import os
|
||||
import time
|
||||
from pathlib import Path
|
||||
from clients.radarr_client import RadarrClient
|
||||
from clients.radarr_db_client import RadarrDbClient
|
||||
|
||||
def test_database_connection():
|
||||
"""Test database connection and basic functionality"""
|
||||
print("=== Testing Database Connection ===")
|
||||
|
||||
db_client = RadarrDbClient.from_env()
|
||||
if not db_client:
|
||||
print("❌ Database client not configured - check environment variables")
|
||||
return False
|
||||
|
||||
print("✅ Database connection successful")
|
||||
|
||||
# Test basic stats
|
||||
stats = db_client.get_database_stats()
|
||||
print(f"Database stats: {stats}")
|
||||
|
||||
return True
|
||||
|
||||
def test_movie_lookup_performance():
|
||||
"""Compare API vs Database performance for movie lookups"""
|
||||
print("\n=== Testing Movie Lookup Performance ===")
|
||||
|
||||
# Test IMDb IDs - adjust these to movies in your library
|
||||
test_imdb_ids = [
|
||||
"tt1596343", # Fast & Furious 6
|
||||
"tt0468569", # The Dark Knight
|
||||
"tt0137523", # Fight Club
|
||||
"tt0109830", # Forrest Gump
|
||||
"tt0111161" # The Shawshank Redemption
|
||||
]
|
||||
|
||||
# Initialize clients
|
||||
radarr_url = os.environ.get("RADARR_URL")
|
||||
radarr_api_key = os.environ.get("RADARR_API_KEY")
|
||||
|
||||
if not radarr_url or not radarr_api_key:
|
||||
print("❌ RADARR_URL and RADARR_API_KEY required for testing")
|
||||
return
|
||||
|
||||
client = RadarrClient(radarr_url, radarr_api_key)
|
||||
|
||||
# Test API performance
|
||||
print("\n--- API Performance ---")
|
||||
api_times = []
|
||||
api_found = 0
|
||||
|
||||
for imdb_id in test_imdb_ids:
|
||||
start_time = time.time()
|
||||
|
||||
# Temporarily disable database client for API-only test
|
||||
original_db_client = client.db_client
|
||||
client.db_client = None
|
||||
|
||||
movie = client.movie_by_imdb(imdb_id)
|
||||
|
||||
# Restore database client
|
||||
client.db_client = original_db_client
|
||||
|
||||
elapsed = time.time() - start_time
|
||||
api_times.append(elapsed)
|
||||
|
||||
if movie:
|
||||
api_found += 1
|
||||
print(f" {imdb_id}: {elapsed:.3f}s - Found: {movie.get('title')}")
|
||||
else:
|
||||
print(f" {imdb_id}: {elapsed:.3f}s - Not found")
|
||||
|
||||
# Test Database performance
|
||||
print("\n--- Database Performance ---")
|
||||
db_times = []
|
||||
db_found = 0
|
||||
|
||||
if client.db_client:
|
||||
for imdb_id in test_imdb_ids:
|
||||
start_time = time.time()
|
||||
movie = client.movie_by_imdb(imdb_id) # This will use database first
|
||||
elapsed = time.time() - start_time
|
||||
db_times.append(elapsed)
|
||||
|
||||
if movie:
|
||||
db_found += 1
|
||||
print(f" {imdb_id}: {elapsed:.3f}s - Found: {movie.get('title')}")
|
||||
else:
|
||||
print(f" {imdb_id}: {elapsed:.3f}s - Not found")
|
||||
else:
|
||||
print(" Database client not available")
|
||||
return
|
||||
|
||||
# Performance comparison
|
||||
print("\n--- Performance Summary ---")
|
||||
avg_api_time = sum(api_times) / len(api_times)
|
||||
avg_db_time = sum(db_times) / len(db_times)
|
||||
|
||||
print(f"API Average: {avg_api_time:.3f}s ({api_found}/{len(test_imdb_ids)} found)")
|
||||
print(f"Database Average: {avg_db_time:.3f}s ({db_found}/{len(test_imdb_ids)} found)")
|
||||
|
||||
if avg_api_time > 0 and avg_db_time > 0:
|
||||
speedup = avg_api_time / avg_db_time
|
||||
print(f"Speedup: {speedup:.1f}x faster with database")
|
||||
|
||||
def test_import_date_performance():
|
||||
"""Test import date retrieval performance"""
|
||||
print("\n=== Testing Import Date Performance ===")
|
||||
|
||||
radarr_url = os.environ.get("RADARR_URL")
|
||||
radarr_api_key = os.environ.get("RADARR_API_KEY")
|
||||
|
||||
if not radarr_url or not radarr_api_key:
|
||||
print("❌ RADARR_URL and RADARR_API_KEY required for testing")
|
||||
return
|
||||
|
||||
client = RadarrClient(radarr_url, radarr_api_key)
|
||||
|
||||
# Find a test movie
|
||||
test_movie = client.movie_by_imdb("tt1596343") # Use database if available
|
||||
if not test_movie:
|
||||
print("❌ Test movie not found in library")
|
||||
return
|
||||
|
||||
movie_id = test_movie.get('id')
|
||||
movie_title = test_movie.get('title', 'Unknown')
|
||||
print(f"Testing with: {movie_title} (ID: {movie_id})")
|
||||
|
||||
# Test API performance
|
||||
print("\n--- API Import Date Performance ---")
|
||||
start_time = time.time()
|
||||
|
||||
# Temporarily disable database client
|
||||
original_db_client = client.db_client
|
||||
client.db_client = None
|
||||
|
||||
api_date, api_source = client.get_movie_import_date(movie_id)
|
||||
|
||||
# Restore database client
|
||||
client.db_client = original_db_client
|
||||
|
||||
api_time = time.time() - start_time
|
||||
print(f"API Result: {api_date} ({api_source}) - {api_time:.3f}s")
|
||||
|
||||
# Test Database performance
|
||||
if client.db_client:
|
||||
print("\n--- Database Import Date Performance ---")
|
||||
start_time = time.time()
|
||||
db_date, db_source = client.get_movie_import_date(movie_id)
|
||||
db_time = time.time() - start_time
|
||||
print(f"Database Result: {db_date} ({db_source}) - {db_time:.3f}s")
|
||||
|
||||
if api_time > 0 and db_time > 0:
|
||||
speedup = api_time / db_time
|
||||
print(f"Import date speedup: {speedup:.1f}x faster with database")
|
||||
else:
|
||||
print("Database client not available for comparison")
|
||||
|
||||
def test_bulk_operations():
|
||||
"""Test bulk import date operations"""
|
||||
print("\n=== Testing Bulk Operations ===")
|
||||
|
||||
db_client = RadarrDbClient.from_env()
|
||||
if not db_client:
|
||||
print("❌ Database client required for bulk operations")
|
||||
return
|
||||
|
||||
# Test bulk import dates
|
||||
test_imdb_ids = ["tt1596343", "tt0468569", "tt0137523", "tt0109830", "tt0111161"]
|
||||
|
||||
start_time = time.time()
|
||||
results = db_client.bulk_import_dates(test_imdb_ids)
|
||||
elapsed = time.time() - start_time
|
||||
|
||||
print(f"Bulk operation completed in {elapsed:.3f}s")
|
||||
print("Results:")
|
||||
for imdb_id, (date_iso, source) in results.items():
|
||||
print(f" {imdb_id}: {date_iso} ({source})")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("NFOGuard Database Performance Test")
|
||||
print("=" * 50)
|
||||
|
||||
# Test database connection
|
||||
if not test_database_connection():
|
||||
print("Exiting due to database connection failure")
|
||||
exit(1)
|
||||
|
||||
# Test movie lookups
|
||||
test_movie_lookup_performance()
|
||||
|
||||
# Test import dates
|
||||
test_import_date_performance()
|
||||
|
||||
# Test bulk operations
|
||||
test_bulk_operations()
|
||||
|
||||
print("\n✅ All tests completed!")
|
||||
print("\nTo enable database access, configure these environment variables:")
|
||||
print(" RADARR_DB_TYPE=postgresql")
|
||||
print(" RADARR_DB_HOST=your_postgres_host")
|
||||
print(" RADARR_DB_PORT=5432")
|
||||
print(" RADARR_DB_NAME=radarr-main")
|
||||
print(" RADARR_DB_USER=postgres")
|
||||
print(" RADARR_DB_PASSWORD=your_password")
|
||||
print("\nOr for SQLite:")
|
||||
print(" RADARR_DB_TYPE=sqlite")
|
||||
print(" RADARR_DB_PATH=/config/radarr.db")
|
||||
Reference in New Issue
Block a user