Skip to content

Commit 3ddb12b

Browse files
authored
Metadata records (#1270)
* Save the metadata directly under the unit doc, which saves us some reads for the dashboard.
1 parent f0ce4e7 commit 3ddb12b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/panoptes/pocs/utils/cli/network.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ def upload_metadata(dir_path: Path = '.', unit_id: str = None, verbose: bool = F
9999
event_handler = FileSystemEventHandler()
100100
firestore_db = firestore.Client()
101101
# Get the unit reference to link metadata to unit.
102-
unit_metadata_ref = firestore_db.document(f'units/{unit_id}/metadata')
103-
metadata_records_ref = unit_metadata_ref.collection('records')
102+
unit_ref = firestore_db.document(f'units/{unit_id}')
103+
metadata_records_ref = unit_ref.collection('metadata')
104104

105105
def handleEvent(event):
106106
if event.is_directory:
@@ -115,19 +115,19 @@ def handleEvent(event):
115115
record = json.loads(Path(event.src_path).read_text())
116116

117117
# Unpack the envelope.
118-
collection = record['type']
118+
record_type = record['type']
119119
data = record['data']
120120
data['date'] = record['date']
121121
data['received_time'] = firestore.SERVER_TIMESTAMP
122122

123123
if verbose:
124-
print(f'Adding data for {collection=}: {data}')
124+
print(f'Adding data for {record_type=}: {data}')
125125

126-
# Update the main "current" record for the unit.
127-
unit_metadata_ref.set({collection: data}, merge=True)
126+
# Update the unit's metadata with the record_type.
127+
unit_ref.set({'metadata': {record_type: data}}, merge=True)
128128

129-
# Add the record, storing the collection name in the data.
130-
data['collection'] = collection
129+
# Add the record, storing the record_type name in the data.
130+
data['record_type'] = record_type
131131
doc_ts, doc_id = metadata_records_ref.add(data)
132132
if verbose:
133133
print(f'Added data to firestore with {doc_id.id=} at {doc_ts}')

0 commit comments

Comments
 (0)