dayhoff-tools 1.1.42__py3-none-any.whl → 1.1.43__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -128,23 +128,58 @@ def publish_cards(
128
128
  names: List[str],
129
129
  firestore_collection: str,
130
130
  ):
131
- """Publish cards to Firebase. Expects a list of filenames (not full paths),
132
- which will each be published as a new document in the collection."""
131
+ """Publish cards to Firebase using batch writes for optimal performance.
132
+
133
+ Expects a list of filenames (not full paths), which will each be published
134
+ as a new document in the collection. Uses Firestore batch writes to minimize
135
+ network round-trips and improve performance.
136
+
137
+ Args:
138
+ names: List of packet filenames to publish as cards
139
+ firestore_collection: Name of the Firestore collection to write to
140
+ """
141
+ if not names:
142
+ print("No cards to upload.")
143
+ return
133
144
 
134
145
  initialize_firebase()
135
- collection = firestore.client().collection(firestore_collection)
146
+ db = firestore.client()
147
+ collection = db.collection(firestore_collection)
148
+
149
+ # Firestore batch limit is 500 operations
150
+ BATCH_SIZE = 500
151
+ total_cards = len(names)
152
+ cards_processed = 0
153
+
154
+ # Process names in batches of up to 500
155
+ for i in range(0, total_cards, BATCH_SIZE):
156
+ batch = db.batch()
157
+ batch_names = names[i : i + BATCH_SIZE]
158
+
159
+ # Add all operations for this batch
160
+ for name in batch_names:
161
+ doc_ref = collection.document() # Auto-generate document ID
162
+ batch.set(
163
+ doc_ref,
164
+ {
165
+ "status": "available",
166
+ "packet_filename": name,
167
+ "created": datetime.now(ZoneInfo("America/Los_Angeles")),
168
+ },
169
+ )
136
170
 
137
- for name in names:
138
- collection.document().set(
139
- {
140
- "status": "available",
141
- "packet_filename": name,
142
- "created": datetime.now(ZoneInfo("America/Los_Angeles")),
143
- }
171
+ # Commit the entire batch atomically
172
+ batch.commit()
173
+ cards_processed += len(batch_names)
174
+
175
+ print(
176
+ f"Batch {i // BATCH_SIZE + 1}: Created {len(batch_names)} cards "
177
+ f"({cards_processed}/{total_cards} total)"
144
178
  )
145
- print(f"Creating card {name}")
146
179
 
147
- print(f"Uploaded {len(names)} cards.")
180
+ print(
181
+ f"Successfully uploaded {total_cards} cards in {(total_cards + BATCH_SIZE - 1) // BATCH_SIZE} batch(es)."
182
+ )
148
183
 
149
184
 
150
185
  @transactional
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dayhoff-tools
3
- Version: 1.1.42
3
+ Version: 1.1.43
4
4
  Summary: Common tools for all the repos at Dayhoff Labs
5
5
  Author: Daniel Martin-Alarcon
6
6
  Author-email: dma@dayhofflabs.com
@@ -12,7 +12,7 @@ dayhoff_tools/deployment/deploy_gcp.py,sha256=xgaOVsUDmP6wSEMYNkm1yRNcVskfdz80qJ
12
12
  dayhoff_tools/deployment/deploy_utils.py,sha256=StFwbqnr2_FWiKVg3xnJF4kagTHzndqqDkpaIOaAn_4,26027
13
13
  dayhoff_tools/deployment/job_runner.py,sha256=hljvFpH2Bw96uYyUup5Ths72PZRL_X27KxlYzBMgguo,5086
14
14
  dayhoff_tools/deployment/processors.py,sha256=LM0CQbr4XCb3AtLbrcuDQm4tYPXsoNqgVJ4WQYDjzJc,12406
15
- dayhoff_tools/deployment/swarm.py,sha256=MGcS2_x4RNFtnVjWlU_SwNfhICz8NlGYr9cYBK4ZKDA,21688
15
+ dayhoff_tools/deployment/swarm.py,sha256=YJfvVOcAS8cYcIj2fiN4qwC2leh0I9w5A4px8ZWSF6g,22833
16
16
  dayhoff_tools/embedders.py,sha256=fRkyWjHo8OmbNUBY_FwrgfvyiLqpmrpI57UAb1Szn1Y,36609
17
17
  dayhoff_tools/fasta.py,sha256=_kA2Cpiy7JAGbBqLrjElkzbcUD_p-nO2d5Aj1LVmOvc,50509
18
18
  dayhoff_tools/file_ops.py,sha256=JlGowvr-CUJFidV-4g_JmhUTN9bsYuaxtqKmnKomm-Q,8506
@@ -26,7 +26,7 @@ dayhoff_tools/intake/uniprot.py,sha256=BZYJQF63OtPcBBnQ7_P9gulxzJtqyorgyuDiPeOJq
26
26
  dayhoff_tools/logs.py,sha256=DKdeP0k0kliRcilwvX0mUB2eipO5BdWUeHwh-VnsICs,838
27
27
  dayhoff_tools/sqlite.py,sha256=jV55ikF8VpTfeQqqlHSbY8OgfyfHj8zgHNpZjBLos_E,18672
28
28
  dayhoff_tools/warehouse.py,sha256=TqV8nex1AluNaL4JuXH5zuu9P7qmE89lSo6f_oViy6U,14965
29
- dayhoff_tools-1.1.42.dist-info/METADATA,sha256=tXnXIVVY3rpyNqyzl8cfzciGdW8ajHlJPpdliTYMD0M,2843
30
- dayhoff_tools-1.1.42.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
31
- dayhoff_tools-1.1.42.dist-info/entry_points.txt,sha256=iAf4jteNqW3cJm6CO6czLxjW3vxYKsyGLZ8WGmxamSc,49
32
- dayhoff_tools-1.1.42.dist-info/RECORD,,
29
+ dayhoff_tools-1.1.43.dist-info/METADATA,sha256=S3WFgeHSXhXJUg6E8nHcSBmbGktzd9B-2A7LIdX1c9k,2843
30
+ dayhoff_tools-1.1.43.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
31
+ dayhoff_tools-1.1.43.dist-info/entry_points.txt,sha256=iAf4jteNqW3cJm6CO6czLxjW3vxYKsyGLZ8WGmxamSc,49
32
+ dayhoff_tools-1.1.43.dist-info/RECORD,,