Skip to content

Commit 0360b6a

Browse files
committed
refactor: remove cache layer from finder methods
1 parent 22842ea commit 0360b6a

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/posit/connect/resources.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,7 @@ def _create_instance(self, path: str, /, **kwargs: Any) -> T:
104104
"""Create an instance of 'T'."""
105105
raise NotImplementedError()
106106

107-
def reload(self) -> Self:
108-
"""Reloads the collection from Connect.
109-
110-
Returns
111-
-------
112-
Self
113-
"""
114-
self._cache = None
115-
return self
116-
117-
def _fetch(self) -> List[T]:
107+
def fetch(self) -> List[T]:
118108
"""Fetch the collection.
119109
120110
Fetches the collection directly from Connect. This operation does not effect the cache state.
@@ -128,6 +118,16 @@ def _fetch(self) -> List[T]:
128118
results = response.json()
129119
return [self._to_instance(result) for result in results]
130120

121+
def reload(self) -> Self:
122+
"""Reloads the collection from Connect.
123+
124+
Returns
125+
-------
126+
Self
127+
"""
128+
self._cache = None
129+
return self
130+
131131
def _to_instance(self, result: dict) -> T:
132132
"""Converts a result into an instance of T."""
133133
uid = result[self._uid]
@@ -150,7 +150,7 @@ def _data(self) -> List[T]:
150150
reload
151151
"""
152152
if self._cache is None:
153-
self._cache = self._fetch()
153+
self._cache = self.fetch()
154154
return self._cache
155155

156156
@overload
@@ -213,4 +213,5 @@ def find_by(self, **conditions: Any) -> Optional[T]:
213213
Optional[T]
214214
The first record matching the conditions, or `None` if no match is found.
215215
"""
216-
return next((v for v in self._data if v.items() >= conditions.items()), None)
216+
collection = self.fetch()
217+
return next((v for v in collection if v.items() >= conditions.items()), None)

0 commit comments

Comments
 (0)