@@ -25,6 +25,7 @@ import org.nypl.simplified.accounts.source.spi.AccountProviderSourceResolutionSt
25
25
import org.nypl.simplified.accounts.source.spi.AccountProviderSourceType
26
26
import org.nypl.simplified.accounts.source.spi.AccountProviderSourceType.SourceResult
27
27
import org.nypl.simplified.files.FileUtilities
28
+ import org.nypl.simplified.links.Link
28
29
import org.nypl.simplified.opds.auth_document.api.AuthenticationDocumentParsersType
29
30
import org.nypl.simplified.parser.api.ParseResult
30
31
import org.nypl.simplified.taskrecorder.api.TaskResult
@@ -35,6 +36,7 @@ import java.io.FileNotFoundException
35
36
import java.io.IOException
36
37
import java.io.InputStream
37
38
import java.net.URI
39
+ import java.time.OffsetDateTime
38
40
39
41
/* *
40
42
* A server-based account provider.
@@ -106,8 +108,10 @@ class AccountProviderSourceNYPLRegistry(
106
108
this .fetchServerResults(includeTestingLibraries)
107
109
val mergedResults =
108
110
this .mergeResults(diskResults, serverResults)
111
+ val target =
112
+ this .decideRegistryURI(includeTestingLibraries)
109
113
110
- this .cacheServerResults(files, mergedResults)
114
+ this .cacheServerResults(files, target, mergedResults)
111
115
SourceResult .SourceSucceeded (mergedResults)
112
116
} catch (e: Exception ) {
113
117
this .logger.debug(" failed to fetch providers: " , e)
@@ -191,6 +195,7 @@ class AccountProviderSourceNYPLRegistry(
191
195
192
196
private fun cacheServerResults (
193
197
cacheFiles : CacheFiles ,
198
+ target : URI ,
194
199
mergedResults : Map <URI , AccountProviderDescription >
195
200
) {
196
201
try {
@@ -203,7 +208,7 @@ class AccountProviderSourceNYPLRegistry(
203
208
val collection =
204
209
AccountProviderDescriptionCollection (
205
210
providers = mergedResults.values.toList(),
206
- links = listOf (),
211
+ links = listOf (Link . LinkBasic (href = target, relation = " self " ) ),
207
212
metadata = meta
208
213
)
209
214
val serializer =
@@ -231,6 +236,8 @@ class AccountProviderSourceNYPLRegistry(
231
236
private fun fetchDiskResults (cacheFiles : CacheFiles ): Map <URI , AccountProviderDescription > {
232
237
this .logger.debug(" fetching disk cache: {}" , cacheFiles.file)
233
238
239
+ val timeThen = OffsetDateTime .now()
240
+
234
241
return try {
235
242
cacheFiles.file.inputStream().use { stream ->
236
243
val parser =
@@ -266,6 +273,11 @@ class AccountProviderSourceNYPLRegistry(
266
273
} catch (e: Exception ) {
267
274
this .logger.debug(" could not load cache file: " , e)
268
275
emptyMap()
276
+ } finally {
277
+ val timeNow = OffsetDateTime .now()
278
+ this .logger.debug(
279
+ " processed cached providers in {}" , java.time.Duration .between(timeThen, timeNow)
280
+ )
269
281
}
270
282
}
271
283
0 commit comments