pycontribs / jira

Python Jira library. Development chat available on https://matrix.to/#/#pycontribs:matrix.org
https://jira.readthedocs.io
BSD 2-Clause "Simplified" License
1.92k stars 857 forks source link

client: Cache raw field information #1798

Open lhh opened 5 months ago

lhh commented 5 months ago

The field JSON from the JIRA server contains important information, such as schemas, which can be used by applications building on this library. Since it's generally preferred, whenever possible, to reduce unnecessary calls to JIRA API endpoints, we can keep this information in the client object.

lhh commented 5 months ago

There doesn't seem to be a way for me apply the label after submitting the PR, but this would fall under 'enhancement'.

lhh commented 5 months ago

The py38 failure seems to be unrelated to the change here.

adehad commented 3 months ago

Have you considered the possibility for using a functools.lru_cache decorator on the method? That would also give us some helper methods, like the ability to clear the cache

(as you say the cloud test failings are unrelated, so no need to worry)

lhh commented 2 months ago

It would be possible to do that.

The rate of change of the information in /rest/api/latest/field is not typically very fast, but it is certainly true that the information does get updated, and that re-fetching it periodically is a good idea in long-running processes.

Presently, the value in _fields_cache_value is not done that way - once it is populated, it is not updated from the JIRA server. This MR follows that precedent.

If we do decide use functools.lru_cache decorator with _fields_cache_value_raw, I think we need to be careful to ensure that the value in _field_cache_value is updated whenever the value of _fields_cache_value_raw is updated; these data sets should be consistent.