Skip to content

Commit 44b1c6c

Browse files
committed
Refactor away extraneous methods
1 parent 9bfe4a9 commit 44b1c6c

File tree

3 files changed

+11
-36
lines changed

3 files changed

+11
-36
lines changed

client_code/_users.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .auto_batch import unwrap_any_input_rows, BatchTable
1+
from .auto_batch import unwrap_any_input_rows, BatchRow
22
import anvil.users
33

44

@@ -7,6 +7,5 @@ def force_login(*args, **kwargs):
77

88

99
def get_user(*args, **kwargs):
10-
user_row = anvil.users.get_user(*args, **kwargs)
11-
batch_table = BatchTable.of_row(user_row)
12-
return batch_table.get_batch_row(user_row)
10+
raw_out = anvil.users.get_user(*args, **kwargs)
11+
return BatchRow(raw_out) if raw_out else None

client_code/auto_batch.py

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def row(self, value):
132132
raise RuntimeError("BatchRow.row already set")
133133
if value:
134134
self._row = value
135-
BatchTable.of_row(self._row).add_batch_row(self)
135+
get_table_by_id(self._row._table_id).add_batch_row(self)
136136

137137
@if_not_deleted
138138
def __eq__(self, other):
@@ -211,13 +211,11 @@ def clear_cache(self):
211211

212212
@portable_class
213213
class BatchSearchIterator(anvil.tables.SearchIterator):
214-
def __init__(self, batch_table, search_iterator):
215-
self._batch_table = batch_table
214+
def __init__(self, search_iterator):
216215
self._search_iterator = search_iterator
217216

218217
def __getitem__(self, index):
219-
row = self._search_iterator[index]
220-
return self._batch_table.get_batch_row(row)
218+
return BatchRow(self._search_iterator[index])
221219

222220
def __len__(self):
223221
return len(self._search_iterator)
@@ -241,25 +239,21 @@ def search(self, *args, **kwargs):
241239
print("AutoBatch: process_batch triggered early by search")
242240
process_batch()
243241
return BatchSearchIterator(
244-
self,
245242
unwrap_any_input_rows(self.table.search)(*args, **kwargs)
246243
)
247244

248245
def get(self, *args, **kwargs):
249246
if _add_queue or _update_queue or _delete_queue:
250247
print("AutoBatch: process_batch triggered early by get")
251248
process_batch()
252-
return self.get_batch_row(
253-
unwrap_any_input_rows(self.table.get)(*args, **kwargs)
254-
)
249+
raw_out = unwrap_any_input_rows(self.table.get)(*args, **kwargs)
250+
return BatchRow(raw_out) if raw_out else None
255251

256252
def get_by_id(self, row_id, *args, **kwargs):
257253
if row_id in self._batch_rows:
258-
batch_row = self._batch_rows[row_id]
254+
return self._batch_rows[row_id]
259255
else:
260-
row = self.table.get_by_id(row_id, *args, **kwargs)
261-
batch_row = BatchRow(row)
262-
return batch_row
256+
return BatchRow(self.table.get_by_id(row_id, *args, **kwargs))
263257

264258
def add_row(self, **column_values):
265259
global _add_queue
@@ -279,20 +273,6 @@ def delete_all_rows(self, *args, **kwargs):
279273
def add_batch_row(self, batch_row):
280274
self._batch_rows[batch_row.get_id()] = batch_row
281275

282-
def has_row_batched(self, row):
283-
return row.get_id() in self._batch_rows
284-
285-
def get_batch_row(self, row):
286-
if row is None:
287-
return None
288-
elif self.has_row_batched(row):
289-
return self.retrieve_batch_row(row)
290-
else:
291-
return BatchRow(row)
292-
293-
def retrieve_batch_row(self, row):
294-
return self._batch_rows[row.get_id()]
295-
296276
def __serialize__(self, global_data):
297277
if _add_queue or _update_queue or _delete_queue:
298278
print("AutoBatch: process_batch triggered early by table __serialize__")
@@ -304,10 +284,6 @@ def clear_cache(self):
304284
batch_row.clear_cache()
305285
#self._batch_rows.clear()
306286

307-
@staticmethod
308-
def of_row(row):
309-
return get_table_by_id(row._table_id)
310-
311287

312288
class BatchTables:
313289
def __init__(self):

client_code/tables/_tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import anvil.tables
22
from . import query
33
from ..auto_batch import batch_tables as app_tables
4-
from ..auto_batch import get_table_by_id, AutoBatch, BatchRow, BatchSearchIterator, BatchTable
4+
from ..auto_batch import get_table_by_id, AutoBatch
55
from functools import wraps
66
#from contextlib import nullcontext
77

0 commit comments

Comments
 (0)