I keep observing it take 3-4s to update the UI after a manual CAPI
request. This showed up as mostly *in*
AppWindow.capi_handle_response(), but the moment I ran it under PyCharm
profile that went down to 400ms.
* The 'EDMC' prefix on all these classes is to make it clear they're for
internal passing around of requests/responses, rather than holding the
literal raw CAPI request and response.
* The request and response queues are now commented, including the
detail that the response queue is created by the caller and then set
'here' by Session.set_capi_response_queue().
* It's no use `dict(CAPIData)` if that contains other `CAPIData`. So,
rather than write something to do that recursively just implement a
simple JSON Encoder class and specify its use.
EDMC.py will also need to make CAPI queries using the new threaded
method, but it has no tkinter, thus we need to pass in the event name
when we expect one to be generated, and only generate it if this is not
None.
It will write a file containing JSON that has a top level dict with a
key per endpoint we have data for, and within each of those a dict with
keys for query_time and the raw_data.
Everything from the opening `{` in that raw_data value until the
matching closing `}` is the raw data from the CAPI service.
The whole file happily goes through `jq -S -C '.'` to examine the
output.
* Using global dict on class CAPIDataRaw as there should only ever be
one of these. *Any* querying of CAPI should record the response data
in this single place.
* But as there'll be multiple endpoints recorded, class
CAPIDataRawEndpoint uses instance variables.
* It is the raw string from
`requests.Response.content.decode(encoding='utf-8')` that is recorded,
not the result of JSON decoding.
* The recording happens in the worker capi_single_query() so it's as
close as possible to where the data came back. The query_time is
allowed to take on the default utc_now() value, rather than matching
the nominal query_time of the request as passed in.
* Base the following on common EDMCCAPIReturn: EDMCFailedrequest,
EDMCCAPIRequest, EDMCCAPIResponse. This saves repeating a bunch of
variable types and comments.
* Use the above throughout the 'Update' button flow.
* Still need to address 'Save Raw Data', i.e. AppWindow.save_raw().
* Still need to change stats.py to use a cached copy of CAPI data,
rather than it querying that itself. That means actually storing that
cached copy whilst in the capi worker.
* Defined inner functions in the worker function to handle the actual
queries. This allows for *them* to simply return data or raise
exceptions to be caught by the main worker function. *IT* then
handles returning any error appropriately via the queue to AppWindow.
* Due to the coupling between AppWindow and these queries there are
several extra parameters passed into the queue worker and then back
out. This is largely due to having to split AppWindow.getandsend()
into two functions: capi_request_data() and capi_handle_response().
This might get changed to use a class to encapsulate those values,
rather than the bare tuple currently being used.
* No full flake8 & mypy pass done yet.
* Some companion.py globals renamed so their use is more obvious.