@@ -150,36 +150,31 @@ func (t *Table) setColumnNameMap() {
150
150
// build map of all hydrate configs, including those specified in the legacy HydrateDependencies,
151
151
// and those mentioned only in column config
152
152
func (t * Table ) buildHydrateConfigMap () {
153
+ // TDO tidy this up - initialise at end, set name first?
153
154
t .hydrateConfigMap = make (map [string ]* HydrateConfig )
154
155
for i := range t .HydrateConfig {
155
156
// as we are converting into a pointer, we cannot use the array value direct from the range as
156
157
// this was causing incorrect values - go must be reusing memory addresses for successive items
157
158
h := & t .HydrateConfig [i ]
158
-
159
- // initialise before adding to map
159
+ // NOTE: initialise the hydrate config
160
160
h .initialise (t )
161
+
161
162
t .hydrateConfigMap [h .namedHydrate .Name ] = h
162
163
}
163
164
// add in hydrate config for all hydrate dependencies declared using legacy property HydrateDependencies
164
165
for _ , d := range t .HydrateDependencies {
165
166
hydrateName := newNamedHydrateFunc (d .Func ).Name
166
- // if there is already a hydrate config, do nothing here
167
+ // if there is already an explicit hydrate config, do nothing here
167
168
// (this is a validation error that will be picked up by the validation check later)
168
169
if _ , ok := t .hydrateConfigMap [hydrateName ]; ! ok {
169
- t .hydrateConfigMap [hydrateName ] = & HydrateConfig {Func : d .Func , Depends : d .Depends }
170
+ // create and initialise a new hydrate config for this func
171
+ t .hydrateConfigMap [hydrateName ] = t .newHydrateConfig (d .Func , d .Depends ... )
170
172
}
171
173
}
172
174
// NOTE: the get config may be used as a column hydrate function so add this into the map
173
175
if get := t .Get ; get != nil {
174
- hydrateName := get .namedHydrate .Name
175
- t .hydrateConfigMap [hydrateName ] = & HydrateConfig {
176
- Func : get .Hydrate ,
177
- IgnoreConfig : get .IgnoreConfig ,
178
- RetryConfig : get .RetryConfig ,
179
- Tags : get .Tags ,
180
- ShouldIgnoreError : get .ShouldIgnoreError ,
181
- MaxConcurrency : get .MaxConcurrency ,
182
- }
176
+ // create and initialise a new hydrate config for the get func
177
+ t .hydrateConfigMap [get .namedHydrate .Name ] = t .hydrateConfigFromGet (t .Get )
183
178
}
184
179
185
180
// now add all hydrate functions with no explicit config
@@ -191,13 +186,35 @@ func (t *Table) buildHydrateConfigMap() {
191
186
hydrateName := newNamedHydrateFunc (c .Hydrate ).Name
192
187
193
188
if _ , ok := t .hydrateConfigMap [hydrateName ]; ! ok {
194
- t .hydrateConfigMap [hydrateName ] = & HydrateConfig {
195
- Func : c .Hydrate ,
196
- }
189
+ t .hydrateConfigMap [hydrateName ] = t .newHydrateConfig (c .Hydrate )
197
190
}
198
191
}
199
192
}
200
193
194
+ func (t * Table ) newHydrateConfig (hydrateFunc HydrateFunc , depends ... HydrateFunc ) * HydrateConfig {
195
+ c := & HydrateConfig {Func : hydrateFunc , Depends : depends }
196
+ // be sure to initialise the config
197
+ c .initialise (t )
198
+ return c
199
+ }
200
+
201
+ func (t * Table ) hydrateConfigFromGet (get * GetConfig ) * HydrateConfig {
202
+ if t .Get == nil {
203
+ return nil
204
+ }
205
+ c := & HydrateConfig {
206
+ Func : get .Hydrate ,
207
+ IgnoreConfig : get .IgnoreConfig ,
208
+ RetryConfig : get .RetryConfig ,
209
+ Tags : get .Tags ,
210
+ ShouldIgnoreError : get .ShouldIgnoreError ,
211
+ MaxConcurrency : get .MaxConcurrency ,
212
+ }
213
+ // be sure to initialise the config
214
+ c .initialise (t )
215
+ return c
216
+ }
217
+
201
218
func (t * Table ) getFetchFunc (fetchType fetchType ) namedHydrateFunc {
202
219
if fetchType == fetchTypeList {
203
220
return * t .List .namedHydrate
0 commit comments