Skip to content

Commit 9e4e1cb

Browse files
feat: sanitizing fetched data in fetch_publications function.
- reduced total token from 74k to 65k
1 parent 8fefa3a commit 9e4e1cb

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

backend/app/services/vcelldb_service.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ async def fetch_publications() -> List[dict]:
322322
Fetch a list of publications from the VCell API.
323323
324324
Returns:
325-
List[dict]: A list of publication dictionaries.
325+
List[dict]: A list of publication dictionaries with sanitized data.
326326
"""
327327
url = f"{VCELL_API_BASE_URL}/publication?submitLow=&submitHigh=&startRow=1&maxRows=1000&hasData=all&waiting=on&queued=on&dispatched=on&running=on"
328328

@@ -336,8 +336,23 @@ async def fetch_publications() -> List[dict]:
336336

337337
# Ensure we return a list of dictionaries
338338
if isinstance(publications, list):
339-
logger.info(f"Successfully fetched {len(publications)} publications")
340-
return publications
339+
# Sanitize publications by removing unwanted fields
340+
sanitized_publications = []
341+
for pub in publications:
342+
if isinstance(pub, dict):
343+
# Create a copy and remove unwanted fields
344+
sanitized_pub = pub.copy()
345+
sanitized_pub.pop('wittid', None)
346+
sanitized_pub.pop('date', None)
347+
sanitized_pub.pop('endnoteid', None)
348+
sanitized_publications.append(sanitized_pub)
349+
else:
350+
# If not a dict, keep as is but log warning
351+
logger.warning(f"Publication is not a dictionary: {type(pub)}")
352+
sanitized_publications.append(pub)
353+
354+
logger.info(f"Successfully fetched and sanitized {len(sanitized_publications)} publications")
355+
return sanitized_publications
341356
else:
342357
logger.warning(f"Unexpected response format: {type(publications)}")
343358
return []

0 commit comments

Comments
 (0)