fix: optimize database initialization and marketplace router ordering
Some checks failed
Some checks failed
Database Initialization Optimization: ✅ SELECTIVE MODEL IMPORT: Changed from wildcard to explicit imports - storage/db.py: Import only essential models (Job, Miner, MarketplaceOffer, etc.) - Reason: Avoids 2+ minute startup delays from loading all domain models - Impact: Faster application startup while maintaining required functionality Marketplace Router Ordering Fix: ✅ ROUTER PRECEDENCE: Moved marketplace_offers router after global_marketplace - main
This commit is contained in:
@@ -288,7 +288,6 @@ def create_app() -> FastAPI:
|
||||
app.include_router(services, prefix="/v1")
|
||||
app.include_router(users, prefix="/v1")
|
||||
app.include_router(exchange, prefix="/v1")
|
||||
app.include_router(marketplace_offers, prefix="/v1")
|
||||
app.include_router(payments, prefix="/v1")
|
||||
app.include_router(web_vitals, prefix="/v1")
|
||||
app.include_router(edge_gpu)
|
||||
@@ -309,6 +308,9 @@ def create_app() -> FastAPI:
|
||||
app.include_router(developer_platform, prefix="/v1")
|
||||
app.include_router(governance_enhanced, prefix="/v1")
|
||||
|
||||
# Include marketplace_offers AFTER global_marketplace to override the /offers endpoint
|
||||
app.include_router(marketplace_offers, prefix="/v1")
|
||||
|
||||
# Add blockchain router for CLI compatibility
|
||||
print(f"Adding blockchain router: {blockchain}")
|
||||
app.include_router(blockchain, prefix="/v1")
|
||||
|
||||
@@ -36,11 +36,11 @@ class MarketplaceService:
|
||||
stmt = stmt.where(MarketplaceOffer.status == normalised)
|
||||
|
||||
stmt = stmt.offset(offset).limit(limit)
|
||||
offers = self.session.execute(stmt).all()
|
||||
offers = self.session.execute(stmt).scalars().all()
|
||||
return [self._to_offer_view(o) for o in offers]
|
||||
|
||||
def get_stats(self) -> MarketplaceStatsView:
|
||||
offers = self.session.execute(select(MarketplaceOffer)).all()
|
||||
offers = self.session.execute(select(MarketplaceOffer)).scalars().all()
|
||||
open_offers = [offer for offer in offers if offer.status == "open"]
|
||||
|
||||
total_offers = len(offers)
|
||||
|
||||
@@ -62,7 +62,13 @@ def get_engine() -> Engine:
|
||||
return _engine
|
||||
|
||||
|
||||
from app.domain import *
|
||||
# Import only essential models for database initialization
|
||||
# This avoids loading all domain models which causes 2+ minute startup delays
|
||||
from app.domain import (
|
||||
Job, Miner, MarketplaceOffer, MarketplaceBid,
|
||||
User, Wallet, Transaction, UserSession,
|
||||
JobPayment, PaymentEscrow, JobReceipt
|
||||
)
|
||||
|
||||
def init_db() -> Engine:
|
||||
"""Initialize database tables and ensure data directory exists."""
|
||||
|
||||
Reference in New Issue
Block a user