@@ -36,8 +36,9 @@ import (
36
36
func (ps * propertiesService ) retrieveAllPropertiesForEntity (
37
37
ctx context.Context , provider provifv1.Provider , entID uuid.UUID ,
38
38
lookupProperties * properties.Properties , entType minderv1.Entity ,
39
- qtx db. ExtendQuerier , l zerolog.Logger ,
39
+ opts * ReadOptions , l zerolog.Logger ,
40
40
) (* properties.Properties , error ) {
41
+ qtx := ps .getStoreOrTransaction (opts )
41
42
42
43
var dbProps []db.Property
43
44
if entID != uuid .Nil {
@@ -61,7 +62,7 @@ func (ps *propertiesService) retrieveAllPropertiesForEntity(
61
62
if err != nil {
62
63
return nil , fmt .Errorf ("failed to convert properties: %w" , err )
63
64
}
64
- if ps .areDatabasePropertiesValid (dbProps ) {
65
+ if ps .areDatabasePropertiesValid (dbProps , opts ) {
65
66
l .Info ().Msg ("properties are valid, skipping provider fetch" )
66
67
return modelProps , nil
67
68
}
@@ -84,7 +85,7 @@ func (ps *propertiesService) retrieveAllPropertiesForEntity(
84
85
}
85
86
86
87
// save updated properties to db, thus making sure that the updatedAt are bumped
87
- err = ps .ReplaceAllProperties (ctx , entID , refreshedProps , qtx )
88
+ err = ps .ReplaceAllProperties (ctx , entID , refreshedProps , opts . getPropertiesServiceCallOptions () )
88
89
if err != nil {
89
90
return nil , fmt .Errorf ("failed to update properties: %w" , err )
90
91
}
@@ -93,15 +94,15 @@ func (ps *propertiesService) retrieveAllPropertiesForEntity(
93
94
return refreshedProps , nil
94
95
}
95
96
96
- func ( ps * propertiesService ) getEntityIdByProperties (
97
+ func getEntityIdByProperties (
97
98
ctx context.Context , projectId uuid.UUID ,
98
99
providerID uuid.UUID ,
99
100
props * properties.Properties , entType minderv1.Entity ,
100
101
qtx db.ExtendQuerier ,
101
102
) (uuid.UUID , error ) {
102
103
upstreamID := props .GetProperty (properties .PropertyUpstreamID )
103
104
if upstreamID != nil {
104
- ent , getErr := ps . getEntityIdByUpstreamID (ctx , projectId , providerID , upstreamID .GetString (), entType , qtx )
105
+ ent , getErr := getEntityIdByUpstreamID (ctx , projectId , providerID , upstreamID .GetString (), entType , qtx )
105
106
if getErr == nil {
106
107
return ent , nil
107
108
} else if ! errors .Is (getErr , ErrEntityNotFound ) {
@@ -114,14 +115,14 @@ func (ps *propertiesService) getEntityIdByProperties(
114
115
// Fall back to name if no upstream ID is provided
115
116
name := props .GetProperty (properties .PropertyName )
116
117
if name != nil {
117
- return ps . getEntityIdByName (ctx , projectId , providerID , name .GetString (), entType , qtx )
118
+ return getEntityIdByName (ctx , projectId , providerID , name .GetString (), entType , qtx )
118
119
}
119
120
120
121
// returning nil ID and nil error would make us just go to the provider. Slow, but we'd continue.
121
122
return uuid .Nil , nil
122
123
}
123
124
124
- func ( _ * propertiesService ) getEntityIdByName (
125
+ func getEntityIdByName (
125
126
ctx context.Context , projectId uuid.UUID ,
126
127
providerID uuid.UUID ,
127
128
name string , entType minderv1.Entity ,
@@ -142,7 +143,7 @@ func (_ *propertiesService) getEntityIdByName(
142
143
return ent .ID , nil
143
144
}
144
145
145
- func ( _ * propertiesService ) getEntityIdByUpstreamID (
146
+ func getEntityIdByUpstreamID (
146
147
ctx context.Context , projectId uuid.UUID ,
147
148
providerID uuid.UUID ,
148
149
upstreamID string , entType minderv1.Entity ,
@@ -173,20 +174,21 @@ func (_ *propertiesService) getEntityIdByUpstreamID(
173
174
return uuid .Nil , ErrEntityNotFound
174
175
}
175
176
176
- func (ps * propertiesService ) areDatabasePropertiesValid (dbProps []db.Property ) bool {
177
+ func (ps * propertiesService ) areDatabasePropertiesValid (
178
+ dbProps []db.Property , opts * ReadOptions ) bool {
177
179
// if the all the properties are to be valid, neither must be older than
178
180
// the cache timeout
179
181
for _ , prop := range dbProps {
180
- if ! ps .isDatabasePropertyValid (prop ) {
182
+ if ! ps .isDatabasePropertyValid (prop , opts ) {
181
183
return false
182
184
}
183
185
}
184
186
return true
185
187
}
186
188
187
- func (ps * propertiesService ) isDatabasePropertyValid (dbProp db. Property ) bool {
188
- if ps . entityTimeout == bypassCacheTimeout {
189
- // this is mostly for testing
189
+ func (ps * propertiesService ) isDatabasePropertyValid (
190
+ dbProp db. Property , opts * ReadOptions ) bool {
191
+ if ps . entityTimeout == bypassCacheTimeout || opts . canTolerateStaleData () {
190
192
return false
191
193
}
192
194
return time .Since (dbProp .UpdatedAt ) < ps .entityTimeout
0 commit comments