Skip to content

Commit

Permalink
Merge pull request #75 from CCRI-POPROX/karl/fix/load-experiment
Browse files Browse the repository at this point in the history
Remove database commit management and account alias creation from experiment/dataset repos
  • Loading branch information
karlhigley authored Feb 18, 2025
2 parents 1ff643f + a54378f commit 9b9101e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
8 changes: 3 additions & 5 deletions src/poprox_storage/repositories/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ def __init__(self, connection: Connection):
)

def store_new_dataset(self, accounts: list[Account], team_id: UUID) -> UUID:
self.conn.commit()
with self.conn.begin():
dataset_id = self._insert_dataset(team_id)
dataset_id = self._insert_dataset(team_id)

for account in accounts:
self._insert_account_alias(dataset_id, account)
for account in accounts:
self._insert_account_alias(dataset_id, account)

return dataset_id

Expand Down
38 changes: 17 additions & 21 deletions src/poprox_storage/repositories/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,24 @@ def store_experiment(
dataset_id: UUID,
):
assignments = assignments or {}
self.conn.commit()
with self.conn.begin():
experiment_id = self._insert_experiment(dataset_id, experiment)

for group in experiment.groups:
group.group_id = self._insert_expt_group(experiment_id, group)
for account in assignments.get(group.name, []):
self._insert_account_alias(dataset_id, account)

assignment = Assignment(account_id=account.account_id, group_id=group.group_id)
self._insert_expt_assignment(assignment)

for recommender in experiment.recommenders:
recommender.recommender_id = self._insert_expt_recommender(
experiment_id,
recommender,
)
experiment_id = self._insert_experiment(dataset_id, experiment)

for group in experiment.groups:
group.group_id = self._insert_expt_group(experiment_id, group)
for account in assignments.get(group.name, []):
assignment = Assignment(account_id=account.account_id, group_id=group.group_id)
self._insert_expt_assignment(assignment)

for recommender in experiment.recommenders:
recommender.recommender_id = self._insert_expt_recommender(
experiment_id,
recommender,
)

for phase in experiment.phases:
phase.phase_id = self._insert_expt_phase(experiment_id, phase)
for treatment in phase.treatments:
self._insert_expt_treatment(phase.phase_id, treatment)
for phase in experiment.phases:
phase.phase_id = self._insert_expt_phase(experiment_id, phase)
for treatment in phase.treatments:
self._insert_expt_treatment(phase.phase_id, treatment)

return experiment_id

Expand Down

0 comments on commit 9b9101e

Please sign in to comment.