Move status context joins to temporary table

This commit is contained in:
Justin Mazzocchi 2020-09-16 20:16:32 -07:00
parent abeded5a6d
commit f2344fcbe9
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
2 changed files with 29 additions and 16 deletions

View file

@ -25,6 +25,7 @@ public struct ContentDatabase {
} }
try Self.migrate(databaseQueue) try Self.migrate(databaseQueue)
try Self.createTemporaryTables(databaseQueue)
} }
} }
@ -73,7 +74,7 @@ public extension ContentDatabase {
try StatusContextJoin.filter( try StatusContextJoin.filter(
Column("parentId") == parentID Column("parentId") == parentID
&& Column("section") == section.rawValue && Column("section") == section.rawValue
&& Column("index") >= statuses.count) && !statuses.map(\.id).contains(Column("statusId")))
.deleteAll($0) .deleteAll($0)
} }
} }
@ -269,21 +270,6 @@ private extension ContentDatabase {
t.primaryKey(["timelineId", "statusId"], onConflict: .replace) t.primaryKey(["timelineId", "statusId"], onConflict: .replace)
} }
try db.create(table: "statusContextJoin") { t in
t.column("parentId", .text)
.indexed()
.notNull()
.references("statusRecord", column: "id", onDelete: .cascade, onUpdate: .cascade)
t.column("statusId", .text)
.indexed()
.notNull()
.references("statusRecord", column: "id", onDelete: .cascade, onUpdate: .cascade)
t.column("section", .text).notNull()
t.column("index", .integer).notNull()
t.primaryKey(["parentId", "statusId"], onConflict: .replace)
}
try db.create(table: "filter") { t in try db.create(table: "filter") { t in
t.column("id", .text).notNull().primaryKey(onConflict: .replace) t.column("id", .text).notNull().primaryKey(onConflict: .replace)
t.column("phrase", .text).notNull() t.column("phrase", .text).notNull()
@ -297,4 +283,21 @@ private extension ContentDatabase {
try migrator.migrate(writer) try migrator.migrate(writer)
} }
// swiftlint:enable function_body_length // swiftlint:enable function_body_length
private static func createTemporaryTables(_ writer: DatabaseWriter) throws {
try writer.write { db in
try db.create(table: "statusContextJoin", temporary: true) { t in
t.column("parentId", .text)
.indexed()
.notNull()
t.column("statusId", .text)
.indexed()
.notNull()
t.column("section", .text).notNull()
t.column("index", .integer).notNull()
t.primaryKey(["parentId", "statusId"], onConflict: .replace)
}
}
}
} }

View file

@ -0,0 +1,10 @@
// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
import GRDB
extension OrderedRequest {
func orderedByIDSequence(_ ids: [String]) -> Self {
fatalError()
}
}