From 7ca5a4313ff2bc22bb39ad2dd0848ad947953f54 Mon Sep 17 00:00:00 2001 From: Elijah Wright Date: Thu, 12 Jun 2025 11:37:26 -0700 Subject: [PATCH] define JSONDecoder() outside of for loop in load() (#159) this PR defines a variable, `decoder`, which represents the `JSONDecoder` class, rather than doing it in the for loop in `load()` Signed-off-by: Elijah Wright --- Sources/ContainerPersistence/EntityStore.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/ContainerPersistence/EntityStore.swift b/Sources/ContainerPersistence/EntityStore.swift index ab1b5ff1..7a09665f 100644 --- a/Sources/ContainerPersistence/EntityStore.swift +++ b/Sources/ContainerPersistence/EntityStore.swift @@ -101,12 +101,13 @@ public actor FilesystemEntityStore: EntityStore where T: Codable & Identifiab private static func load(path: URL, log: Logger) throws -> Index { let directories = try FileManager.default.contentsOfDirectory(at: path, includingPropertiesForKeys: nil) var index: FilesystemEntityStore.Index = Index() + let decoder = JSONDecoder() for entityUrl in directories { do { let metadataUrl = entityUrl.appendingPathComponent(metadataFilename) let data = try Data(contentsOf: metadataUrl) - let entity = try JSONDecoder().decode(T.self, from: data) + let entity = try decoder.decode(T.self, from: data) index[entity.id] = entity } catch { log.warning(