Spaces:
Paused
Paused
Commit ·
4f4cfa4
1
Parent(s): 9d20b05
feat(project): remove heavy nested collections from project customer response for performance improvement
Browse files- app/controllers/projects.py +10 -2
- app/schemas/project_detail.py +1 -3
- app/services/project_service.py +2 -26
app/controllers/projects.py
CHANGED
|
@@ -50,7 +50,11 @@ def get_project(project_no: int, db: Session = Depends(get_db)):
|
|
| 50 |
return service.get_detail_no_customers(project_no)
|
| 51 |
|
| 52 |
|
| 53 |
-
@router.get(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
def get_project_customers(
|
| 55 |
project_no: int,
|
| 56 |
page: Optional[int] = Query(1, description="Page number (1-indexed)", ge=1),
|
|
@@ -68,7 +72,11 @@ def get_project_customers(
|
|
| 68 |
return service.get_customers(project_no, page=page, page_size=page_size, last_id=last_id)
|
| 69 |
|
| 70 |
|
| 71 |
-
@router.get(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
def get_project_customer_detail(
|
| 73 |
project_no: int,
|
| 74 |
customer_id: str,
|
|
|
|
| 50 |
return service.get_detail_no_customers(project_no)
|
| 51 |
|
| 52 |
|
| 53 |
+
@router.get(
|
| 54 |
+
"/{project_no}/customers",
|
| 55 |
+
response_model=List[ProjectCustomerOut],
|
| 56 |
+
response_model_exclude={"barrier_sizes", "contacts", "bidder_notes"}
|
| 57 |
+
)
|
| 58 |
def get_project_customers(
|
| 59 |
project_no: int,
|
| 60 |
page: Optional[int] = Query(1, description="Page number (1-indexed)", ge=1),
|
|
|
|
| 72 |
return service.get_customers(project_no, page=page, page_size=page_size, last_id=last_id)
|
| 73 |
|
| 74 |
|
| 75 |
+
@router.get(
|
| 76 |
+
"/{project_no}/customers/{customer_id}",
|
| 77 |
+
response_model=ProjectCustomerOut,
|
| 78 |
+
response_model_exclude={"barrier_sizes", "contacts", "bidder_notes"}
|
| 79 |
+
)
|
| 80 |
def get_project_customer_detail(
|
| 81 |
project_no: int,
|
| 82 |
customer_id: str,
|
app/schemas/project_detail.py
CHANGED
|
@@ -59,9 +59,7 @@ class ProjectCustomerOut(BaseModel):
|
|
| 59 |
quote_date: Optional[datetime] = Field(None, description="Quote date")
|
| 60 |
invoice_date: Optional[datetime] = Field(None, description="Invoice date")
|
| 61 |
less_payment: Optional[Decimal] = Field(None, description="Less payment amount")
|
| 62 |
-
|
| 63 |
-
contacts: List[ContactOut] = Field(default_factory=list, description="Customer contacts")
|
| 64 |
-
bidder_notes: List[BidderNoteOut] = Field(default_factory=list, description="Bidder notes")
|
| 65 |
bid_date: Optional[datetime] = Field(None, description="Bid date")
|
| 66 |
enabled: bool = Field(True, description="Customer enabled status")
|
| 67 |
employee_id: Optional[str] = Field(None, description="Employee ID")
|
|
|
|
| 59 |
quote_date: Optional[datetime] = Field(None, description="Quote date")
|
| 60 |
invoice_date: Optional[datetime] = Field(None, description="Invoice date")
|
| 61 |
less_payment: Optional[Decimal] = Field(None, description="Less payment amount")
|
| 62 |
+
# Permanently removed heavy nested collections to improve performance
|
|
|
|
|
|
|
| 63 |
bid_date: Optional[datetime] = Field(None, description="Bid date")
|
| 64 |
enabled: bool = Field(True, description="Customer enabled status")
|
| 65 |
employee_id: Optional[str] = Field(None, description="Employee ID")
|
app/services/project_service.py
CHANGED
|
@@ -166,29 +166,7 @@ class ProjectService:
|
|
| 166 |
|
| 167 |
bidder_id = bidder_data.get('Id')
|
| 168 |
|
| 169 |
-
#
|
| 170 |
-
contacts_rows = bidder_repo.get_bidder_contacts_raw(bidder_id)
|
| 171 |
-
barrier_sizes = []
|
| 172 |
-
|
| 173 |
-
# Map contacts
|
| 174 |
-
contacts = []
|
| 175 |
-
for cr in contacts_rows:
|
| 176 |
-
contacts.append(ContactOut(
|
| 177 |
-
id=cr.get('Id'),
|
| 178 |
-
contact_id=cr.get('ContactId'),
|
| 179 |
-
bidder_id=bidder_id,
|
| 180 |
-
enabled=bool(cr.get('Enabled', True)),
|
| 181 |
-
first_name=cr.get('FirstName'),
|
| 182 |
-
last_name=cr.get('LastName'),
|
| 183 |
-
title=cr.get('Title'),
|
| 184 |
-
email=cr.get('EmailAddress'),
|
| 185 |
-
phones=[],
|
| 186 |
-
phone1=cr.get('WorkPhone'),
|
| 187 |
-
phone2=cr.get('MobilePhone')
|
| 188 |
-
))
|
| 189 |
-
|
| 190 |
-
# Skip bidder notes
|
| 191 |
-
bidder_notes = []
|
| 192 |
|
| 193 |
# Create customer object with proper type conversions
|
| 194 |
replacement_cost = bidder_data.get('replacement_cost')
|
|
@@ -222,9 +200,7 @@ class ProjectService:
|
|
| 222 |
quote_date=bidder_data.get('quote_date'),
|
| 223 |
invoice_date=bidder_data.get('invoice_date'),
|
| 224 |
less_payment=bidder_data.get('less_payment'),
|
| 225 |
-
barrier_sizes
|
| 226 |
-
contacts=contacts,
|
| 227 |
-
bidder_notes=bidder_notes,
|
| 228 |
bid_date=bidder_data.get('date_last_contact'), # Using last contact as bid date
|
| 229 |
enabled=bool(bidder_data.get('enabled', True)),
|
| 230 |
employee_id=str(bidder_data.get('employee_id')) if bidder_data.get('employee_id') is not None else None
|
|
|
|
| 166 |
|
| 167 |
bidder_id = bidder_data.get('Id')
|
| 168 |
|
| 169 |
+
# Heavy nested collections permanently removed: contacts, barrier sizes, bidder notes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
# Create customer object with proper type conversions
|
| 172 |
replacement_cost = bidder_data.get('replacement_cost')
|
|
|
|
| 200 |
quote_date=bidder_data.get('quote_date'),
|
| 201 |
invoice_date=bidder_data.get('invoice_date'),
|
| 202 |
less_payment=bidder_data.get('less_payment'),
|
| 203 |
+
# Removed barrier_sizes, contacts, bidder_notes
|
|
|
|
|
|
|
| 204 |
bid_date=bidder_data.get('date_last_contact'), # Using last contact as bid date
|
| 205 |
enabled=bool(bidder_data.get('enabled', True)),
|
| 206 |
employee_id=str(bidder_data.get('employee_id')) if bidder_data.get('employee_id') is not None else None
|