gristlabs_grist-core/sandbox
Alex Hall fb09b7afa0 (core) Avoid quadratic time complexity in fetch_table with query
Summary: While looking at webhooks code, I noticed that it calls `ActiveDoc.fetchQuery` (which I think typically leads to the sandbox method `fetch_table`) with a query on the `id` column, where the values could potentially be all row IDs in the table (e.g. if a new column was added, as in a recent discussion about webhooks gone wrong). This suggests that `fetch_table` should try to avoid using a list for values when possible. In practice this only starts to become an issue at about 10k rows, so I don't know if this has caused any real problems, but it seemed like something worth fixing.

Test Plan:
Extended unit tests for correctness. Tested performance manually. Made a doc with this formula:

```
import time
row_ids = list(Table2.table.row_ids)
query = {"id": row_ids}
start = time.time()
result = table.table._engine.fetch_table('Table2', query=query)
end = time.time()
assert result[1] == row_ids
end - start, len(row_ids)
```

Then put a bunch of rows in `Table2`. This diff made the returned elapsed time much less.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Subscribers: jarek

Differential Revision: https://phab.getgrist.com/D4092
2023-11-03 13:24:05 +02:00
..
docker (core) Upgrade to Python 3.11 2023-08-04 18:19:40 +02:00
grist (core) Avoid quadratic time complexity in fetch_table with query 2023-11-03 13:24:05 +02:00
gvisor (core) Upgrade to Python 3.11 2023-08-04 18:19:40 +02:00
pyodide remove cached packages for pyodide when cleaning up (#650) 2023-08-29 15:21:34 -04:00
bundle_as_wheel.sh support other SQLite wrappers, and various hooks needed by grist-static (#516) 2023-05-23 15:17:28 -04:00
gen_js_schema.py add a script for copying schema information from python to typescript 2023-01-17 15:54:41 -05:00
install_tz.js (core) apply some dependabot suggestions 2022-09-07 14:15:34 -04:00
MANIFEST.in support other SQLite wrappers, and various hooks needed by grist-static (#516) 2023-05-23 15:17:28 -04:00
requirements3.in (core) Upgrade to Python 3.11 2023-08-04 18:19:40 +02:00
requirements3.txt (core) Fix updating attributes inside f-strings when columns are renamed 2023-09-11 14:41:30 +02:00
requirements.txt (core) Fix updating attributes inside f-strings when columns are renamed 2023-09-11 14:41:30 +02:00
run.sh (core) add machinery for self-managed flavor of Grist 2022-05-12 12:39:52 -04:00
setup.py support other SQLite wrappers, and various hooks needed by grist-static (#516) 2023-05-23 15:17:28 -04:00
watch.sh Add command to debug the server (#533) 2023-06-20 12:49:57 -04:00