Skip to content

Commit 81094fa

Browse files
committed
Removed caching placeholder
1 parent 645afc6 commit 81094fa

1 file changed

Lines changed: 22 additions & 60 deletions

File tree

Sources/Compiler/Driver.swift

Lines changed: 22 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,16 @@ public actor Driver {
4949

5050
let migrationFiles = try fileSystem.files(atPath: migrationsPath)
5151
let queriesFiles = try fileSystem.files(atPath: queriesPath)
52-
let cache = try loadCache(for: path)
5352

5453
// Migrations must be run synchronously in order.
5554
for migration in migrationFiles {
56-
try compile(
57-
file: migration,
58-
in: migrationsPath,
59-
usage: .migration,
60-
cache: cache
61-
)
55+
try compile(file: migration, in: migrationsPath, usage: .migration)
6256
}
6357

6458
// Queries can be compiled independently
6559
try await withThrowingTaskGroup(of: Void.self) { group in
6660
for query in queriesFiles {
67-
try compile(
68-
file: query,
69-
in: queriesPath,
70-
usage: .queries,
71-
cache: cache
72-
)
61+
try compile(file: query, in: queriesPath, usage: .queries)
7362
}
7463

7564
try await group.waitForAll()
@@ -90,7 +79,6 @@ public actor Driver {
9079
.flatMap(\.statements)
9180
.map(\.sanitizedSource)
9281

93-
9482
// An array of all queries grouped by their file name
9583
let queries = results.values
9684
.filter{ $0.usage == .queries }
@@ -120,55 +108,36 @@ public actor Driver {
120108
}
121109
}
122110

123-
private func compile(
124-
file: String,
125-
in base: Path,
126-
usage: Usage,
127-
cache: [Path: Output]
128-
) throws {
111+
private func compile(file: String, in base: Path, usage: Usage) throws {
129112
let path = "\(base)/\(file)"
130113
let fileContents = try fileSystem.contents(of: path)
131114
let modificationDate = try fileSystem.modificationDate(of: path)
115+
116+
var compiler = Compiler()
117+
compiler.schema = currentSchema
132118

133-
let output: Output
134-
let newSchema: Schema
135-
// See if cache is usable
136-
if let cached = cache[file],
137-
let previousModificationDate = cached.modificationDate,
138-
modificationDate == previousModificationDate {
139-
// Has not been modified since the last compilation so reuse it.
140-
output = cached
141-
newSchema = cached.schema
142-
} else {
143-
var compiler = Compiler()
144-
compiler.schema = currentSchema
145-
146-
let diagnostics = switch usage {
147-
case .migration, .alwaysMigration:
148-
compiler.compile(migration: fileContents, namespace: .global)
149-
case .queries:
150-
compiler.compile(queries: fileContents, namespace: .global)
151-
}
152-
153-
newSchema = compiler.schema
154-
output = Output(
155-
fileName: file,
156-
usage: usage,
157-
diagnostics: diagnostics,
158-
statements: compiler.queries.flatMap(\.1),
159-
schema: compiler.schema,
160-
modificationDate: modificationDate
161-
)
162-
163-
load(diagnostics: diagnostics, source: fileContents, fileName: file)
119+
let diagnostics = switch usage {
120+
case .migration, .alwaysMigration:
121+
compiler.compile(migration: fileContents, namespace: .global)
122+
case .queries:
123+
compiler.compile(queries: fileContents, namespace: .global)
164124
}
165125

166-
results[file] = output
126+
load(diagnostics: diagnostics, source: fileContents, fileName: file)
127+
128+
results[file] = Output(
129+
fileName: file,
130+
usage: usage,
131+
diagnostics: diagnostics,
132+
statements: compiler.queries.flatMap(\.1),
133+
schema: compiler.schema,
134+
modificationDate: modificationDate
135+
)
167136

168137
// Really this probably could always be set since queries cannot
169138
// affect schema but still worth doing.
170139
if usage == .migration {
171-
currentSchema = newSchema
140+
currentSchema = compiler.schema
172141
}
173142
}
174143

@@ -178,13 +147,6 @@ public actor Driver {
178147
}
179148
}
180149

181-
private func loadCache(for path: Path) throws -> [Path: Output] {
182-
// TODO: This is actually going to be a bit more work.
183-
// TODO: Making `Statement` `Codable` is going to quite the change
184-
// let cachePath = fileSystem.cachePath.appending("/com.wickwire.otter/\(path)")
185-
return [:]
186-
}
187-
188150
/// The migrations path relative to the base path
189151
private func migrationsPath(at base: Path) -> Path {
190152
"\(base)/Migrations"

0 commit comments

Comments
 (0)