fix: 修改数据安装事务提交机制

This commit is contained in:
xiaoyan 2023-09-05 16:58:46 +08:00
parent cfa1041f7e
commit b1e5e30880
2 changed files with 10 additions and 8 deletions

View File

@ -168,14 +168,15 @@ class ImportOMDBHelper @AssistedInject constructor(
// 遍历解压后的文件,读取该数据返回
for (importConfig in importConfigList) {
val realm = Realm.getDefaultInstance()
try {
for ((index, currentEntry) in importConfig.tableMap.entries.withIndex()) {
realm.beginTransaction()
val currentConfig = currentEntry.value
val txtFile = unZipFiles.find {
it.name == currentConfig.table
}
// 将listResult数据插入到Realm数据库中
val realm = Realm.getDefaultInstance()
val listResult = mutableListOf<RenderEntity>()
currentConfig?.let {
val list = FileIOUtils.readFile2List(txtFile, "UTF-8")
@ -619,24 +620,25 @@ class ImportOMDBHelper @AssistedInject constructor(
}
}
listResult.add(renderEntity)
realm.insert(renderEntity)
}
}
}
}
// 1个文件发送一次flow流
emit("${++processIndex}/${tableNum}")
realm.beginTransaction()
realm.insert(listResult)
realm.commitTransaction()
realm.close()
// 如果当前解析的是OMDB_RD_LINK数据将其缓存在预处理类中以便后续处理其他要素时使用
if (currentConfig.table == "OMDB_RD_LINK") {
importConfig.preProcess.cacheRdLink =
listResult.associateBy { it.properties["linkPid"] }
}
realm.commitTransaction()
// 1个文件发送一次flow流
emit("${++processIndex}/${tableNum}")
}
} catch (e: Exception) {
realm.cancelTransaction()
throw e
} finally {
realm.close()
}
}
emit("finish")

2
vtm

@ -1 +1 @@
Subproject commit 985dc0a0d590ef6f6784ee2ee5c1c148dff1c46d
Subproject commit a087521b6e1b312d7ed2bdf20f83b0e674fad9b5