Skip to content

Commit bc71767

Browse files
committed
Doublecheck project on secondary load
1 parent 45eb4c8 commit bc71767

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

activity_browser/bwutils/metadata/loader.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def load_project(self):
3737
# start loading threads
3838
thread = SecondaryLoadThread(self)
3939
thread.done.connect(self.secondary_load_project)
40-
thread.start(databases=list(bd.databases))
40+
thread.start(databases=list(bd.databases), sqlite_db=str(sqlite3_lci_db._filepath))
4141

4242
# load primary metadata in the main thread
4343
self.primary_load_project()
@@ -56,8 +56,11 @@ def primary_load_project(self):
5656
for idx in primary_df.index:
5757
self.mds.register_mutation(idx, "add")
5858

59-
def secondary_load_project(self, secondary_df: pd.DataFrame):
60-
assert len(secondary_df) == len(self.mds.dataframe)
59+
def secondary_load_project(self, secondary_df: pd.DataFrame, sqlite_db: str):
60+
if sqlite_db != str(sqlite3_lci_db._filepath):
61+
return
62+
63+
assert all(secondary_df.index.isin(self.mds.dataframe.index))
6164
log.debug(f"Secondary metadata loaded with {len(secondary_df)} rows")
6265
self.mds.dataframe = pd.concat([self.mds.dataframe[primary], secondary_df], axis=1)
6366

@@ -68,7 +71,7 @@ def load_database(self, database_name: str):
6871
# start loading threads
6972
thread = SecondaryLoadThread(self)
7073
thread.done.connect(self.secondary_load_database)
71-
thread.start(databases=[database_name])
74+
thread.start(databases=[database_name], sqlite_db=str(sqlite3_lci_db._filepath))
7275

7376
# load primary metadata in the main thread
7477
self.primary_load_database(database_name)
@@ -87,8 +90,8 @@ def primary_load_database(self, database_name: str):
8790
for idx in primary_df.index:
8891
self.mds.register_mutation(idx, "add")
8992

90-
def secondary_load_database(self, secondary_df: pd.DataFrame):
91-
if secondary_df.empty:
93+
def secondary_load_database(self, secondary_df: pd.DataFrame, sqlite_db: str):
94+
if secondary_df.empty or sqlite_db != str(sqlite3_lci_db._filepath):
9295
return
9396

9497
database = secondary_df.index[0][0]
@@ -115,10 +118,10 @@ def _fix_categories(self, df: pd.DataFrame):
115118

116119

117120
class SecondaryLoadThread(threading.ABThread):
118-
done: QtCore.SignalInstance = QtCore.Signal(pd.DataFrame)
121+
done: QtCore.SignalInstance = QtCore.Signal(pd.DataFrame, str)
119122

120-
def run_safely(self, databases: list[str], *args, **kwargs):
121-
processes = [self.open_load_process(db) for db in databases]
123+
def run_safely(self, databases: list[str], sqlite_db: str):
124+
processes = [self.open_load_process(db, sqlite_db) for db in databases]
122125

123126
full_df = pd.DataFrame()
124127
for proc in processes:
@@ -132,13 +135,13 @@ def run_safely(self, databases: list[str], *args, **kwargs):
132135

133136
full_df = pd.concat([full_df, df])
134137

135-
self.done.emit(full_df)
138+
self.done.emit(full_df, sqlite_db)
136139

137-
def open_load_process(self, database_name: str):
140+
def open_load_process(self, database_name: str, sqlite_db: str) -> subprocess.Popen:
138141
import activity_browser.bwutils.metadata._sub_loader as sl
139142

140143
return subprocess.Popen(
141-
[sys.executable, sl.__file__, str(sqlite3_lci_db._filepath), database_name] + secondary,
144+
[sys.executable, sl.__file__, str(sqlite_db), database_name] + secondary,
142145
stdout=subprocess.PIPE,
143146
stderr=subprocess.PIPE
144147
)

0 commit comments

Comments
 (0)