fix: optimize database initialization and marketplace router ordering
Some checks failed
Integration Tests / test-service-integration (push) Failing after 6s
Python Tests / test-python (push) Failing after 1m10s
API Endpoint Tests / test-api-endpoints (push) Successful in 1m31s
Security Scanning / security-scan (push) Successful in 1m34s

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:
aitbc
2026-03-30 22:49:01 +02:00
parent f646bd7ed4
commit f061051ec4
3 changed files with 12 additions and 4 deletions

View File

@@ -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")

View File

@@ -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)

View File

@@ -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."""