-
Notifications
You must be signed in to change notification settings - Fork 18
Partial context updates #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 156 commits
Commits
Show all changes
438 commits
Select commit
Hold shift + click to select a range
50cda47
put benchmark tutorial after partial updates one
RLKRo 4cc055a
Merge branch 'dev' into feat/partial_context_updates
pseusys 7f77c8f
context storages updated
pseusys 2617255
old naming reset
pseusys 4fb8f67
context merge fixed
pseusys 1230d16
context ids removed
pseusys c3d82da
context equality tested
pseusys 0bd6347
framework data comparison removed
pseusys 4a15bf0
context id removed from everywhere
pseusys 9b3dd80
lint applied
pseusys 4f0562a
documentation building fixed
pseusys ef0a9ee
RST syntax fixed
pseusys 3d364bc
context dict added
pseusys e7ad269
async + pydantic
pseusys be34714
fixes
pseusys b8701a0
hashes manipulation only on `write_full_diff`
pseusys a58eace
ctx_dict + ctx updated
pseusys 33f2823
setting removed
pseusys c4f9fce
sets added
pseusys e892a52
serialization added, sample context storage class created
pseusys 1b8aa0d
iterative async access made synchronous
pseusys 173b1fe
sql prototype
pseusys 9665038
context API updated proposal
pseusys 3468af5
context schema and serializer removed
pseusys 71bd9f3
context API updated once again
pseusys 2e6b334
review notes fixed
pseusys 830ea40
ContextDictView made mutable
pseusys 5d3dd95
context dict file split
pseusys f00ba02
turn introduction reverted
pseusys 1af24db
turns separated (again)
pseusys 3616ac0
key deletion now nullifies value
pseusys 81ce7ba
memory storage
pseusys 1f9e653
ctx_dict tests done
pseusys c981cc5
general context storages tests created
pseusys 5002dda
ctx_dict updated not to use serializer
pseusys 3e6a8f4
merge dev
RLKRo 6991fb6
Merge branch 'refs/heads/dev' into feat/partial_context_updates
RLKRo 5b80818
fix imports in newly added files
RLKRo 96af9bc
hide circular imports behind type checking
RLKRo 000fb0d
fix imports in test files
RLKRo 2c2ab9d
merge context.init into context.connected
RLKRo 2eb5a2c
remove get_last_index imports
RLKRo 06d54b9
update pipeline.context_storage type
RLKRo f80e6a3
fix bug with setting sequence type values under a single key
RLKRo c5311f6
revert primary_id renaming
RLKRo d43752a
memory test (almost!) finished
pseusys 1ae3e4f
ctx_dict tests fixed
pseusys 85315a6
add overload for getitem
RLKRo 351a43e
split typevar definitions
RLKRo e9eb2fb
remove asyncio mark
RLKRo 6d93399
allow using negative indexes for context dict
RLKRo e2053dc
add validation on setitem for context dict
RLKRo acdcd3c
fixes
RLKRo 16a3d77
allow non-str context ids
RLKRo 9a76ae3
add current_turn_id
RLKRo 5e37651
fix tests
RLKRo d376e49
update doc
RLKRo 256e296
integer keysreversed
pseusys e2ffa0a
sql storage update function fix
pseusys 9043dca
move context factory and pipeline fixtures to global conftest
RLKRo d58ce7c
unbound V from BaseModel
RLKRo 6905bcd
remove default marker; return None by default
RLKRo 0ac3c1e
fix key slicing
RLKRo 3956348
use current_turn_id in check_happy_path
RLKRo d37c4e2
use context_factory to initialize context in non-core tests
RLKRo 2bf82f9
fix: await misc get
RLKRo 8a4d8be
update pipeline tutorials
RLKRo 6404eb4
allow initializing MemoryContextStoraeg via context_storage_factory
RLKRo 240cded
move all db tests into a single parametrized test class
RLKRo 535d524
SQL testing fixed
pseusys 6e0a103
Merge branch 'feat/partial_context_updates' of https://github.com/dee…
pseusys 862e7d3
test_dbs fixed
pseusys e82d086
file context storages implemented
pseusys 59f91c1
file and sql fixed
pseusys 1c97303
async file dependency removed
pseusys f5ceb2f
rename delete_main_info to delete_context
RLKRo cf27afa
fix load_field_items typing
RLKRo c1a24ee
rewrite db tests
RLKRo f2ec013
Merge branch 'refs/heads/dev' into feat/partial_context_updates
RLKRo cb22d12
small None checking update
pseusys 8ba5aed
Merge branch 'feat/partial_context_updates' of https://github.com/dee…
pseusys d9b95f6
tests updated
pseusys 7277bf9
mongo done
pseusys e1cb50d
redis done
pseusys 782bf66
ydb finished
pseusys 0fb487b
raise error in abstract method
RLKRo ff70324
update service tests
RLKRo b59cf95
Merge remote-tracking branch 'origin/feat/partial_context_updates' in…
RLKRo d3af3b2
update lock file
RLKRo e38e2d4
fieldconfig removed
pseusys de739f2
update benchmark utils
RLKRo eaa8a87
aiofile reverted
pseusys 53bf877
misc tables removed
pseusys 7629fbc
Merge branch 'feat/partial_context_updates' of https://github.com/dee…
pseusys 757fe48
denchmark awaiting removed
pseusys a001c27
Merge branch 'refs/heads/dev' into feat/partial_context_updates
RLKRo 96d05dc
update lock file
RLKRo 1430544
fix context size calculation
RLKRo 403e2e1
change model_dump mode
RLKRo 5340256
key filter implementation
pseusys 9aad1bb
Merge branch 'feat/partial_context_updates' of https://github.com/dee…
pseusys b32b367
ctx_dict hashes update added
pseusys edc85bd
added and removed sets cleared upon storage
pseusys e61b1b7
Revert "key filter implementation"
RLKRo d114d42
sql and file logging added
pseusys 3619125
Merge branch 'feat/partial_context_updates' of https://github.com/dee…
pseusys 5618484
debug logging added
pseusys 5e6e223
use standard logging practices
RLKRo 4323871
make logging more uniform across the methods and collapse long lists
RLKRo 93144df
fix potential error in prefix parsing
RLKRo 83c7b33
Merge branch 'refs/heads/dev' into feat/partial_context_updates
RLKRo b763f21
create tmp file only for file dbs
RLKRo 69d1520
add test for load_field_items
RLKRo 291396f
test fix: misc no longer context dict
RLKRo c3d8c73
test fix: load_field_items no longer returns dict
RLKRo 4bb6ca7
test fix: field config was removed
RLKRo dbbbb28
remove debug artefact
RLKRo 710554c
all user input escapedin ydb
pseusys 20b6b5f
ctx_dict moved
pseusys 2b6eebf
async lock introduced
pseusys 6c458c6
codestyle fixed
pseusys 46e0112
Merge branch 'dev' into feat/partial_context_updates
pseusys e263fa1
SOME of the errors FIXED!!!
pseusys 1f96f6d
rebuild script updated
pseusys ce6c8b6
turns added, empty ctx_dict method also added
pseusys 9e7cf47
context creation field set removed
pseusys c34f8e7
contex storage class splitted
pseusys 1d3859c
rebuild was cleaned (once again)
pseusys 5514c7b
turns added and tested
pseusys 2b9b947
splitted database methods + locks and validations
pseusys 86d745c
insert limit removed
pseusys 214fb92
_locks removed from subclasses
pseusys 5a8d0d5
lazy connection
pseusys abbd920
uuid length and name changed
pseusys b9a0680
logs location changed
pseusys 0115b83
none and empty subscript forbidden
pseusys 0587881
names extracted to a special class
pseusys e756f75
set strings removed
pseusys 61619e3
configuration name changed
pseusys aad2c49
literal keys instead of strings
pseusys 539005d
loggers from SQL removed
pseusys 2feb094
connect before load in file
pseusys 2ac91a2
logging moved to commect
pseusys f4e5f33
context dict made abstract
pseusys 68a1c5f
connect moved to pipeline.run
pseusys 8671233
ctx_dict overloads fixed
pseusys 48b6444
configuration renamed
pseusys e40786c
context_info dataclass added
pseusys a54df18
test-time comparison fixed
pseusys 49d3bff
lock staticmethod extracted
pseusys 6fd0e1a
initial locking system fixed
pseusys 47edbda
codestyle
pseusys 567fdb1
id_length moved to init arguments
5d5879d
tutorial updated
c19947f
Merge branch 'refs/heads/dev' into feat/partial_context_updates
RLKRo 95b7cbe
fix: use context factory in slot partial extraction tests
RLKRo fcf3739
revert misc await
RLKRo cdca730
another documentation update
3d73555
Merge remote-tracking branch 'origin/feat/partial_context_updates' in…
RLKRo 683f23d
lint fixed
78c7d7c
tests fixed
59b0aa0
mini-fix for context copy :)
28e2d25
synchronization attempt!
b5eb543
explicit connect made mandatory
9317cb1
context storage initialization rules relaxed
1441814
doc fixed and one silly error also fixed
52fd530
generic removed at all :(
7ba5b39
last generic remains removed
pseusys 1f04c35
overloaded methods added
pseusys ba602b3
serializer and validator replaced
pseusys da1f4bc
super validate and serialize model methods made static
pseusys 7d9bdb6
serializer and validator added to context dict generic class
pseusys a540fbc
naming conflict resolved
pseusys b1f9e68
validators names changed
pseusys e3e24f2
child class validator and serializer removed
pseusys bb6a41d
fix type adapter typing
RLKRo bd37d13
potential warnings fixed
pseusys 60231e5
subscript set test added
pseusys c85ef7e
clear all test added and also small YDB set fix
pseusys 0cfebbe
lint fixed
pseusys 03ddeab
Merge remote-tracking branch 'origin/feat/partial_context_updates' in…
RLKRo b2dca52
remove unnecessary union
RLKRo e01e739
coverage increased further
pseusys e23de94
fix indent in context dict serialization test
RLKRo eaccf80
overload setitem signature
RLKRo e0a0996
lint
RLKRo 0ef6d97
context guide tutorial update prototype
10ae3b1
formatting fixed
ad67ade
fix incorrect rewrite_existing flag usage & add tests
RLKRo 6ae396a
context storing API updated
c67dd72
legacy API removed from tests
817cb67
context updating fixture updated
1e529b7
old API remains removed
502bb15
some more tests updated
e110c06
field validation returned
7baf4a9
field name fixed
68b2d1e
sql length updated
aa02ef4
mongo session introduced
25675be
motor asyncio transaction
10619a4
mongo and postgres updated AGAIN
50b0ce5
mongo transacrion made optional
0820450
import fixed
87ec2a0
few more tests fixed
3646271
one more small redis update
191303b
SQL column binary defaults added
25a0b7d
empty SQL queries not sent
1a6efa7
different field updates collapsed
f4eb249
assignment changed
9677882
lint applied
ff6661c
sql updates separated
9148970
docs updated and type updated
758c65e
add documentation for context dict fields and module
RLKRo 55e5fff
minor changes to tutorial text
RLKRo 86ac873
Merge remote-tracking branch 'origin/feat/partial_context_updates' in…
RLKRo 57a147c
update rewrite existing tests
RLKRo 882f030
update context info signature changed
ee2b967
context data moved away from context file
37bd14d
one method name corrected
fdb3db9
context info field naming updated
2213fe8
method transformed to class property
83bd9ad
async transaction
0135c57
context fields moved to utils
0caa820
pool size added
af64ae2
updated something :)
5ad4676
no query sessions anymore :/
3eff1b8
rewrite iter and add test
RLKRo 95d92f4
newly-published fields excluded
b117591
lint fixed
9b7781e
field name fixed
6ca4523
docs updated
a6710a5
simplify len method
RLKRo fade481
improve contains method
RLKRo 6ca6c95
update get, set, del methods
RLKRo cd18511
Merge remote-tracking branch 'origin/feat/partial_context_updates' in…
RLKRo 018a1a1
Merge branch 'refs/heads/dev' into feat/partial_context_updates
RLKRo deece52
format
RLKRo 4dd6886
remove popitem method
RLKRo 9adbd3c
use elif for consistency
RLKRo 3d11e0b
fix get method and add tests
RLKRo 3a1ce0e
add key in TypeError message
RLKRo 3c3123d
improve doc for ctx_dict and ctx_utils
RLKRo f428849
improve documentation for last_... properties
RLKRo c8d0eea
make turns a property that returns an object with getitem
RLKRo 1a49709
fix history-reliant conditions
RLKRo 77344b2
remove exclamation marks from exception messages
RLKRo e64b4c7
revert last_response raising on no responses
RLKRo 96f2a30
update subscript typing to allow set of int
RLKRo 9fa0332
update user guide and tutorial
RLKRo c00b4f9
fix exclamation mark in raise tests
RLKRo 261a21c
fix db docstrings
RLKRo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| dist/ | ||
| venv/ | ||
| build/ | ||
| dbs/ | ||
| docs/source/apiref | ||
| docs/source/release_notes.rst | ||
| docs/source/tutorials | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| from asyncio import gather | ||
| from datetime import datetime | ||
| from uuid import uuid4 | ||
| from enum import Enum | ||
| from pydantic import BaseModel, Field | ||
| from typing import Any, Coroutine, List, Dict, Optional, Callable, Tuple, Union, Awaitable | ||
| from typing_extensions import Literal | ||
|
|
||
| from dff.script import Context | ||
|
|
||
| ALL_ITEMS = "__all__" | ||
| """ | ||
| `__all__` - the default value for all `DictSchemaField`s: | ||
| it means that all keys of the dictionary or list will be read or written. | ||
| Can be used as a value of `subscript` parameter for `DictSchemaField`s and `ListSchemaField`s. | ||
| """ | ||
|
|
||
| _ReadPackedContextFunction = Callable[[str], Awaitable[Tuple[Dict, Optional[str]]]] | ||
RLKRo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # TODO! | ||
|
|
||
| _ReadLogContextFunction = Callable[[Optional[int], str, str], Awaitable[Dict]] | ||
| # TODO! | ||
|
|
||
| _WritePackedContextFunction = Callable[[Dict, datetime, datetime, str, str], Awaitable] | ||
| # TODO! | ||
|
|
||
| _WriteLogContextFunction = Callable[[List[Tuple[str, int, Any]], datetime, str], Coroutine] | ||
| # TODO! | ||
|
|
||
|
|
||
| class SchemaField(BaseModel): | ||
| """ | ||
| Schema for context fields that are dictionaries with numeric keys fields. | ||
| Used for controlling read / write policy of the particular field. | ||
| """ | ||
|
|
||
| name: str = Field("", allow_mutation=False) | ||
| """ | ||
| `name` is the name of backing Context field. | ||
| It can not (and should not) be changed in runtime. | ||
| """ | ||
|
|
||
| subscript: Union[Literal["__all__"], int] = 3 | ||
| """ | ||
| `subscript` is used for limiting keys for reading and writing. | ||
| It can be a string `__all__` meaning all existing keys or number, | ||
| positive for first **N** keys and negative for last **N** keys. | ||
pseusys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Keys should be sorted as numbers. | ||
| Default: -3. | ||
pseusys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
|
|
||
| class Config: | ||
| validate_assignment = True | ||
|
|
||
|
|
||
| class ExtraFields(str, Enum): | ||
RLKRo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| Enum, conaining special :py:class:`dff.script.Context` field names. | ||
| These fields only can be used for data manipulation within context storage. | ||
| """ | ||
|
|
||
| active_ctx = "active_ctx" | ||
pseusys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| primary_id = "_primary_id" | ||
| storage_key = "_storage_key" | ||
| created_at = "_created_at" | ||
| updated_at = "_updated_at" | ||
|
|
||
|
|
||
| class ContextSchema(BaseModel): | ||
pseusys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| Schema, describing how :py:class:`dff.script.Context` fields should be stored and retrieved from storage. | ||
| Allows fields ignoring, filtering, sorting and partial reading and writing of dictionary fields. | ||
| """ | ||
|
|
||
| requests: SchemaField = Field(SchemaField(name="requests"), allow_mutation=False) | ||
pseusys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| Field for storing Context field `requests`. | ||
pseusys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
|
|
||
| responses: SchemaField = Field(SchemaField(name="responses"), allow_mutation=False) | ||
pseusys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| Field for storing Context field `responses`. | ||
| """ | ||
|
|
||
| labels: SchemaField = Field(SchemaField(name="labels"), allow_mutation=False) | ||
pseusys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| Field for storing Context field `labels`. | ||
| """ | ||
|
|
||
| append_single_log: bool = True | ||
|
|
||
| duplicate_context_in_logs: bool = False | ||
|
|
||
| supports_async: bool = False | ||
|
|
||
| class Config: | ||
| validate_assignment = True | ||
| arbitrary_types_allowed = True | ||
|
|
||
| def __init__(self, **kwargs): | ||
| super().__init__(**kwargs) | ||
|
|
||
| async def read_context(self, pac_reader: _ReadPackedContextFunction, log_reader: _ReadLogContextFunction, storage_key: str) -> Context: | ||
| """ | ||
| Read context from storage. | ||
| Calculate what fields (and what keys of what fields) to read, call reader function and cast result to context. | ||
| `pac_reader` - the function used for context reading from a storage (see :py:const:`~._ReadContextFunction`). | ||
| `storage_key` - the key the context is stored with (used in cases when the key is not preserved in storage). | ||
| `primary_id` - the context unique identifier. | ||
| returns tuple of context and context hashes | ||
| (hashes should be kept and passed to :py:func:`~.ContextSchema.write_context`). | ||
| """ | ||
| ctx_dict, primary_id = await pac_reader(storage_key) | ||
| if primary_id is None: | ||
| raise KeyError(f"No entry for key {primary_id}.") | ||
|
|
||
| tasks = dict() | ||
| for field_props in [value for value in dict(self).values() if isinstance(value, SchemaField)]: | ||
| field_name = field_props.name | ||
| nest_dict = ctx_dict[field_name] | ||
| if isinstance(field_props.subscript, int): | ||
| sorted_dict = sorted(list(nest_dict.keys())) | ||
| last_read_key = sorted_dict[-1] if len(sorted_dict) > 0 else 0 | ||
| if len(nest_dict) > field_props.subscript: | ||
| last_keys = sorted(nest_dict.keys())[-field_props.subscript:] | ||
| ctx_dict[field_name] = {k: v for k, v in nest_dict.items() if k in last_keys} | ||
| elif len(nest_dict) < field_props.subscript and last_read_key > field_props.subscript: | ||
pseusys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| limit = field_props.subscript - len(nest_dict) | ||
| tasks[field_name] = log_reader(limit, field_name, primary_id) | ||
| else: | ||
| tasks[field_name] = log_reader(None, field_name, primary_id) | ||
|
|
||
| if self.supports_async: | ||
| tasks = dict(zip(tasks.keys(), await gather(*tasks.values()))) | ||
| else: | ||
| tasks = {key: await task for key, task in tasks.items()} | ||
|
|
||
| for field_name in tasks.keys(): | ||
| log_dict = {k: v for k, v in tasks[field_name].items()} | ||
| ctx_dict[field_name].update(log_dict) | ||
pseusys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ctx = Context.cast(ctx_dict) | ||
| setattr(ctx, ExtraFields.primary_id.value, primary_id) | ||
| setattr(ctx, ExtraFields.storage_key.value, storage_key) | ||
| return ctx | ||
|
|
||
| async def write_context( | ||
| self, | ||
| ctx: Context, | ||
| pac_writer: _WritePackedContextFunction, | ||
| log_writer: _WriteLogContextFunction, | ||
| storage_key: str, | ||
| chunk_size: Union[Literal[False], int] = False, | ||
pseusys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ): | ||
| """ | ||
| Write context to storage. | ||
| Calculate what fields (and what keys of what fields) to write, | ||
| split large data into chunks if needed and call writer function. | ||
| `ctx` - the context to write. | ||
| `hashes` - hashes calculated for context during previous reading, | ||
| used only for :py:const:`~.SchemaFieldReadPolicy.UPDATE_HASHES`. | ||
| `val_writer` - the function used for context writing to a storage (see :py:const:`~._WriteContextFunction`). | ||
| `storage_key` - the key the context is stored with. | ||
| `primary_id` - the context unique identifier, | ||
| should be None if this is the first time writing this context, | ||
| otherwise the context will be overwritten. | ||
| `chunk_size` - chunk size for large dictionaries writing, | ||
| should be set to integer in case the storage has any writing query limitations, | ||
| otherwise should be boolean `False` or number `0`. | ||
| returns string, the context primary id. | ||
| """ | ||
| updated_at = datetime.now() | ||
| setattr(ctx, ExtraFields.updated_at.value, updated_at) | ||
| created_at = getattr(ctx, ExtraFields.created_at.value, updated_at) | ||
|
|
||
| ctx_dict = ctx.dict() | ||
| logs_dict = dict() | ||
| primary_id = getattr(ctx, ExtraFields.primary_id.value, str(uuid4())) | ||
RLKRo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| for field_props in [value for value in dict(self).values() if isinstance(value, SchemaField)]: | ||
| nest_dict = ctx_dict[field_props.name] | ||
| last_keys = sorted(nest_dict.keys()) | ||
|
|
||
| if self.append_single_log and isinstance(field_props.subscript, int) and len(nest_dict) > field_props.subscript: | ||
| unfit = -field_props.subscript - 1 | ||
pseusys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| logs_dict[field_props.name] = {last_keys[unfit]: nest_dict[last_keys[unfit]]} | ||
| else: | ||
| if self.duplicate_context_in_logs or not isinstance(field_props.subscript, int): | ||
| logs_dict[field_props.name] = nest_dict | ||
| else: | ||
| logs_dict[field_props.name] = {key: nest_dict[key] for key in last_keys[:-field_props.subscript]} | ||
|
|
||
| if isinstance(field_props.subscript, int): | ||
| last_keys = last_keys[-field_props.subscript:] | ||
|
|
||
| ctx_dict[field_props.name] = {k: v for k, v in nest_dict.items() if k in last_keys} | ||
|
|
||
| await pac_writer(ctx_dict, created_at, updated_at, storage_key, primary_id) | ||
|
|
||
| flattened_dict: List[Tuple[str, int, Dict]] = list() | ||
| for field, payload in logs_dict.items(): | ||
| for key, value in payload.items(): | ||
| flattened_dict += [(field, key, value)] | ||
| if len(flattened_dict) > 0: | ||
| if not bool(chunk_size): | ||
| await log_writer(flattened_dict, updated_at, primary_id) | ||
RLKRo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| else: | ||
| tasks = list() | ||
| for ch in range(0, len(flattened_dict), chunk_size): | ||
| next_ch = ch + chunk_size | ||
| chunk = flattened_dict[ch:next_ch] | ||
| tasks += [log_writer(chunk, updated_at, primary_id)] | ||
| if self.supports_async: | ||
| await gather(*tasks) | ||
pseusys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| else: | ||
| for task in tasks: | ||
| await task | ||
|
|
||
| setattr(ctx, ExtraFields.primary_id.value, primary_id) | ||
| setattr(ctx, ExtraFields.storage_key.value, storage_key) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.