bugfix fetching transactions to make use of db cache
This commit is contained in:
parent
9b2653ce91
commit
296a4e7603
5 changed files with 71 additions and 586656 deletions
|
|
@ -45,28 +45,24 @@ async def dump_listings(
|
|||
listings.append(listing)
|
||||
|
||||
# if listing is already in db, do not fetch details again
|
||||
all_listings = await repository.get_listings(
|
||||
only_ids=[listing.identifier for listing in listings],
|
||||
query_parameters=parameters,
|
||||
)
|
||||
all_listing_ids = {listing.id for listing in all_listings}
|
||||
|
||||
listings_without_details = [
|
||||
listing for listing in listings if not listing.path_detail_json().exists()
|
||||
all_listing_ids = [l.id for l in await repository.get_listings()]
|
||||
missing_listing = [
|
||||
listing for listing in listings if listing.identifier not in all_listing_ids
|
||||
]
|
||||
listing_details = await tqdm.gather(
|
||||
*[
|
||||
_fetch_detail_with_semaphore(semaphore, listing.identifier)
|
||||
for listing in listings_without_details
|
||||
if listing.identifier not in all_listing_ids
|
||||
for listing in missing_listing
|
||||
],
|
||||
desc="Fetching details (only missing)",
|
||||
)
|
||||
for listing, detail in zip(listings_without_details, listing_details):
|
||||
for listing, detail in zip(missing_listing, listing_details):
|
||||
listing._details_object = detail
|
||||
|
||||
await dump_listings_to_fs(listings)
|
||||
model_listings = await repository.upsert_listings_legacy(listings) # upsert in db
|
||||
await dump_listings_to_fs(missing_listing)
|
||||
model_listings = await repository.upsert_listings_legacy(
|
||||
missing_listing
|
||||
) # upsert in db
|
||||
|
||||
return model_listings
|
||||
|
||||
|
|
@ -104,9 +100,8 @@ async def _fetch_detail_with_semaphore(
|
|||
|
||||
|
||||
async def dump_listings_to_fs(listings: list[Listing]) -> None:
|
||||
for listing in listings:
|
||||
if not listing.path_listing_json().exists():
|
||||
listing.dump_listing()
|
||||
if not listing.path_detail_json().exists():
|
||||
with open(listing.path_detail_json(), "w") as f:
|
||||
json.dump(listing._details_object, f, indent=4)
|
||||
for listing in tqdm(listings, desc="Dumping listings to FS"):
|
||||
listing.dump_listing()
|
||||
# if not listing.path_detail_json().exists():
|
||||
with open(listing.path_detail_json(), "w") as f:
|
||||
json.dump(listing._details_object, f, indent=4)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue