Skip to content

Commit

Permalink
Add do_postimport flag to importers, allowing postimport to be skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
jessemortenson committed Oct 25, 2023
1 parent 897d6e9 commit db7af4d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions openstates/importers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ class BaseImporter:
merge_related: typing.Dict[str, typing.List[str]] = {}
cached_transformers: _TransformerMapping = {}

def __init__(self, jurisdiction_id: str) -> None:
def __init__(self, jurisdiction_id: str, do_postimport=True) -> None:
self.jurisdiction_id = jurisdiction_id
self.do_postimport = do_postimport
self.json_to_db_id: typing.Dict[str, _ID] = {}
self.duplicates: typing.Dict[str, str] = {}
self.pseudo_id_cache: typing.Dict[str, typing.Optional[_ID]] = {}
Expand Down Expand Up @@ -305,8 +306,8 @@ def import_data(
record[what] += 1

# all objects are loaded, a perfect time to do inter-object resolution and other tasks
if self.json_to_db_id:
# only do postimport step if there are some items of this type
if self.json_to_db_id and self.do_postimport:
# only do postimport step if requested by client code AND there are some items of this type
# resolution of bills take a long time if not
# and events & votes get deleted!
self.postimport()
Expand Down
4 changes: 2 additions & 2 deletions openstates/importers/bills.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class BillImporter(BaseImporter):
}
preserve_order = {"actions"}

def __init__(self, jurisdiction_id: str):
super(BillImporter, self).__init__(jurisdiction_id)
def __init__(self, jurisdiction_id: str, do_postimport=True):
super(BillImporter, self).__init__(jurisdiction_id, do_postimport)
self.org_importer = OrganizationImporter(jurisdiction_id)

def get_object(self, bill: _JsonDict) -> Model:
Expand Down
3 changes: 2 additions & 1 deletion openstates/importers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ def __init__(
self,
jurisdiction_id: str,
vote_event_importer: VoteEventImporter,
do_postimport=True,
):
super(EventImporter, self).__init__(jurisdiction_id)
super(EventImporter, self).__init__(jurisdiction_id, do_postimport)
self.org_importer = OrganizationImporter(jurisdiction_id)
self.vote_event_importer = vote_event_importer

Expand Down
4 changes: 2 additions & 2 deletions openstates/importers/vote_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class VoteEventImporter(BaseImporter):
"sources": (VoteSource, "vote_event_id", {}),
}

def __init__(self, jurisdiction_id: str, bill_importer: BillImporter):
super(VoteEventImporter, self).__init__(jurisdiction_id)
def __init__(self, jurisdiction_id: str, bill_importer: BillImporter, do_postimport=True):
super(VoteEventImporter, self).__init__(jurisdiction_id, do_postimport)
self.org_importer = OrganizationImporter(jurisdiction_id)
self.bill_importer = bill_importer
self.seen_bill_ids: typing.Set[str] = set()
Expand Down

0 comments on commit db7af4d

Please sign in to comment.