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 <git@elijahs.space>
This commit is contained in:
Elijah Wright
2025-06-12 11:37:26 -07:00
committed by GitHub
parent 6f1f770a4e
commit 7ca5a4313f
@@ -101,12 +101,13 @@ public actor FilesystemEntityStore<T>: 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<T>.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(