Skip to content

Commit 224efed

Browse files
committed
Merge branch 'main' into zack-192-git-repo-settings
* main: refactor: removes cache layer from active sequence (#320)
2 parents 0ccf961 + 1dacc4d commit 224efed

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/posit/connect/resources.py

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

116-
def reload(self) -> Self:
117-
"""Reloads the collection from Connect.
118-
119-
Returns
120-
-------
121-
Self
122-
"""
123-
self._cache = None
124-
return self
125-
126-
def _fetch(self) -> List[T]:
116+
def fetch(self) -> List[T]:
127117
"""Fetch the collection.
128118
129119
Fetches the collection directly from Connect. This operation does not effect the cache state.
@@ -137,6 +127,16 @@ def _fetch(self) -> List[T]:
137127
results = response.json()
138128
return [self._to_instance(result) for result in results]
139129

130+
def reload(self) -> Self:
131+
"""Reloads the collection from Connect.
132+
133+
Returns
134+
-------
135+
Self
136+
"""
137+
self._cache = None
138+
return self
139+
140140
def _to_instance(self, result: dict) -> T:
141141
"""Converts a result into an instance of T."""
142142
uid = result[self._uid]
@@ -159,7 +159,7 @@ def _data(self) -> List[T]:
159159
reload
160160
"""
161161
if self._cache is None:
162-
self._cache = self._fetch()
162+
self._cache = self.fetch()
163163
return self._cache
164164

165165
@overload
@@ -171,6 +171,9 @@ def __getitem__(self, index: slice) -> Sequence[T]: ...
171171
def __getitem__(self, index):
172172
return self._data[index]
173173

174+
def __iter__(self):
175+
return iter(self._data)
176+
174177
def __len__(self) -> int:
175178
return len(self._data)
176179

@@ -222,4 +225,5 @@ def find_by(self, **conditions: Any) -> Optional[T]:
222225
Optional[T]
223226
The first record matching the conditions, or `None` if no match is found.
224227
"""
225-
return next((v for v in self._data if v.items() >= conditions.items()), None)
228+
collection = self.fetch()
229+
return next((v for v in collection if v.items() >= conditions.items()), None)

0 commit comments

Comments
 (0)