From: Alexandre Huff Date: Fri, 17 Dec 2021 11:04:48 +0000 (-0300) Subject: Fix caching of error code data not happening X-Git-Tag: 3.0.2~2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=ric-plt%2Fxapp-frame-py.git;a=commitdiff_plain;h=2def417a499bb979f7156d3baf52450e8168fbcf Fix caching of error code data not happening The state_to_status() function re-generates the mapping dict on every call, which could negatively affect performance. This change only generates the mapping dict on first call and caches it for subsequent calls. Issue-Id: RIC-862 Signed-off-by: Alexandre Huff Change-Id: Ida25c5d1f08b4b82e100b6c67ffe911bb8093224 --- diff --git a/ricxappframe/rmr/rmrclib/rmrclib.py b/ricxappframe/rmr/rmrclib/rmrclib.py index 953b76f..c26ffe1 100644 --- a/ricxappframe/rmr/rmrclib/rmrclib.py +++ b/ricxappframe/rmr/rmrclib/rmrclib.py @@ -97,9 +97,13 @@ def get_mapping_dict(cache={}): def state_to_status(stateno): """ - Converts a msg state integer to a status string. + Converts a msg state integer to a status string and caches for subsequent calls. Returns "UNKNOWN STATE" if the int value is not known. """ - sdict = get_mapping_dict() - return sdict.get(stateno, "UNKNOWN STATE") + try: + return state_to_status.sdict.get(stateno, "UNKNOWN STATE") + except AttributeError: # sdict does not exist on first call + state_to_status.sdict = get_mapping_dict() + + return state_to_status.sdict.get(stateno, "UNKNOWN STATE")