1
1
import uuid
2
+ from functools import wraps
2
3
from typing import List , Optional
3
4
4
5
from feast import usage
23
24
from feast .stream_feature_view import StreamFeatureView
24
25
25
26
27
+ def registry_proto_cache (func ):
28
+ cache_key = None
29
+ cache_value = None
30
+
31
+ @wraps (func )
32
+ def wrapper (registry_proto : RegistryProto , project : str ):
33
+ nonlocal cache_key , cache_value
34
+
35
+ key = tuple ([id (registry_proto ), registry_proto .version_id , project ])
36
+
37
+ if key == cache_key :
38
+ return cache_value
39
+ else :
40
+ cache_value = func (registry_proto , project )
41
+ cache_key = key
42
+ return cache_value
43
+
44
+ return wrapper
45
+
46
+
26
47
def init_project_metadata (cached_registry_proto : RegistryProto , project : str ):
27
48
new_project_uuid = f"{ uuid .uuid4 ()} "
28
49
usage .set_current_project_uuid (new_project_uuid )
@@ -137,8 +158,9 @@ def get_validation_reference(
137
158
raise ValidationReferenceNotFound (name , project = project )
138
159
139
160
161
+ @registry_proto_cache
140
162
def list_feature_services (
141
- registry_proto : RegistryProto , project : str , allow_cache : bool = False
163
+ registry_proto : RegistryProto , project : str
142
164
) -> List [FeatureService ]:
143
165
feature_services = []
144
166
for feature_service_proto in registry_proto .feature_services :
@@ -147,6 +169,7 @@ def list_feature_services(
147
169
return feature_services
148
170
149
171
172
+ @registry_proto_cache
150
173
def list_feature_views (
151
174
registry_proto : RegistryProto , project : str
152
175
) -> List [FeatureView ]:
@@ -157,6 +180,7 @@ def list_feature_views(
157
180
return feature_views
158
181
159
182
183
+ @registry_proto_cache
160
184
def list_request_feature_views (
161
185
registry_proto : RegistryProto , project : str
162
186
) -> List [RequestFeatureView ]:
@@ -169,6 +193,7 @@ def list_request_feature_views(
169
193
return feature_views
170
194
171
195
196
+ @registry_proto_cache
172
197
def list_stream_feature_views (
173
198
registry_proto : RegistryProto , project : str
174
199
) -> List [StreamFeatureView ]:
@@ -181,6 +206,7 @@ def list_stream_feature_views(
181
206
return stream_feature_views
182
207
183
208
209
+ @registry_proto_cache
184
210
def list_on_demand_feature_views (
185
211
registry_proto : RegistryProto , project : str
186
212
) -> List [OnDemandFeatureView ]:
@@ -193,6 +219,7 @@ def list_on_demand_feature_views(
193
219
return on_demand_feature_views
194
220
195
221
222
+ @registry_proto_cache
196
223
def list_entities (registry_proto : RegistryProto , project : str ) -> List [Entity ]:
197
224
entities = []
198
225
for entity_proto in registry_proto .entities :
@@ -201,6 +228,7 @@ def list_entities(registry_proto: RegistryProto, project: str) -> List[Entity]:
201
228
return entities
202
229
203
230
231
+ @registry_proto_cache
204
232
def list_data_sources (registry_proto : RegistryProto , project : str ) -> List [DataSource ]:
205
233
data_sources = []
206
234
for data_source_proto in registry_proto .data_sources :
@@ -209,6 +237,7 @@ def list_data_sources(registry_proto: RegistryProto, project: str) -> List[DataS
209
237
return data_sources
210
238
211
239
240
+ @registry_proto_cache
212
241
def list_saved_datasets (
213
242
registry_proto : RegistryProto , project : str
214
243
) -> List [SavedDataset ]:
@@ -219,6 +248,7 @@ def list_saved_datasets(
219
248
return saved_datasets
220
249
221
250
251
+ @registry_proto_cache
222
252
def list_validation_references (
223
253
registry_proto : RegistryProto , project : str
224
254
) -> List [ValidationReference ]:
@@ -231,6 +261,7 @@ def list_validation_references(
231
261
return validation_references
232
262
233
263
264
+ @registry_proto_cache
234
265
def list_project_metadata (
235
266
registry_proto : RegistryProto , project : str
236
267
) -> List [ProjectMetadata ]:
0 commit comments