Skip to content

Commit

Permalink
feat(Sync): fetch OFF obsolete products (25k items) (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn authored Nov 7, 2024
1 parent 2f53957 commit badec8b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions open_prices/common/openfoodfacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ def get_product_dict(product, flavor=Flavor.off) -> JSONType | None:
return None


def import_product_db(flavor: Flavor = Flavor.off, batch_size: int = 1000) -> None:
def import_product_db(
flavor: Flavor = Flavor.off, obsolete: bool = False, batch_size: int = 1000
) -> None:
"""Import from DB JSONL dump to create/update product table.
:param db: the session to use
Expand All @@ -133,7 +135,7 @@ def import_product_db(flavor: Flavor = Flavor.off, batch_size: int = 1000) -> No
"""
from open_prices.products.models import Product

print((f"Launching import_product_db ({flavor})"))
print((f"Launching import_product_db (flavor={flavor}, obsolete={obsolete})"))
existing_product_codes = set(Product.objects.values_list("code", flat=True))
existing_product_flavor_codes = set(
Product.objects.filter(source=flavor).values_list("code", flat=True)
Expand All @@ -146,6 +148,7 @@ def import_product_db(flavor: Flavor = Flavor.off, batch_size: int = 1000) -> No
dataset_type=DatasetType.jsonl,
force_download=True,
download_newer=True,
obsolete=obsolete,
)

seen_codes = set()
Expand Down
1 change: 1 addition & 0 deletions open_prices/common/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

def import_off_db_task():
import_product_db(flavor=Flavor.off)
import_product_db(flavor=Flavor.off, obsolete=True)


def import_obf_db_task():
Expand Down

0 comments on commit badec8b

Please sign in to comment.