我在 Vapor 中使用带有函数“makeNode”的“模型”,当表列数量小于 14 时,我可以成功构建和运行项目。但是当我的表列达到 19 或 20 时,Vapor 启动构建非常非常缓慢,最终会报告失败。我尝试过使用 MySQL 或 MongoDB,都遇到了同样的问题。所以我想知道当我需要使用包含 20 列的表时如何解决这个问题。以下是详细信息:
final class TableName: Model {
var id: Node?
var column1: Int
var column2: Int
var column3: String
var column4: String
var column5: String
var column6: String
var column7: String
var column8: String
var column9: String
var column10: String
var column11: String
var column12: String
var column13: String
var column14: String
var column15: String
var column16: String
var createdAt: Double
var updatedAt: Double
init(column1: Int, column2: Int, column3: String, column4: String, column5: String, column6: String, column7: String, column8, column9: String, column10: String, column11: String, column12: String, column13: String, column14: String, column15: String, column16: String, createdAt: Double, updatedAt: Double) {
self.id = UUID().uuidString.makeNode()
self.column1 = column1
self.column2 = column2
self.column3 = column3
self.column4 = column4
self.column5 = column5
self.column6 = column6
self.column7 = column7
self.column8 = column8
self.column9 = column9
self.column10 = column10
self.column11 = column11
self.column12 = column12
self.column13 = column13
self.column14 = column14
self.column15 = column15
self.column16 = column16
self.createdAt = createdAt
self.updatedAt = updatedAt
}
init(node: Node, in context: Context) throws {
id = try node.extract("id")
column1 = try node.extract("column1")
column2 = try node.extract("column2")
// from 2~16, etc... don't repeat here...
updatedAt = try node.extract("updatedAt")
createdAt = try node.extract("createdAt")
}
// Issue happened here...
// when the amount less than about 10, results are ok and build fast,
// but will build slowly and slowly when the number goes more and more,
// even build failed when table columns goes to about 18~20.
func makeNode(context: Context) throws -> Node {
var node = try Node(node: [
"id": id,
"column1": column1,
"column2": column2,
"column3": column3,
"column4": column4,
"column5": column5,
"column6": column6,
"column7": column7,
"column8": column8,
"column9": column9,
"column10": column10,
"column11": column11,
"column12": column12,
"column13": column13,
"column14": column14,
"column15": column15,
"column16": column16,
"createdAt": createdAt,
"updatedAt": updatedAt
])
return node
}
}
构建错误消息是:
由于信号而导致命令失败:杀死:9
因此,如果您能给我任何提示来解决此问题,我将不胜感激。谢谢你。