fix: 修改realm插入大量数据OOM问题

This commit is contained in:
xiaoyan 2023-09-06 09:31:07 +08:00
parent b1e5e30880
commit ab266bce3e
2 changed files with 46 additions and 48 deletions

View File

@ -177,7 +177,7 @@ class ImportOMDBHelper @AssistedInject constructor(
it.name == currentConfig.table
}
// 将listResult数据插入到Realm数据库中
val listResult = mutableListOf<RenderEntity>()
// val listResult = mutableListOf<RenderEntity>()
currentConfig?.let {
val list = FileIOUtils.readFile2List(txtFile, "UTF-8")
Log.d("ImportOMDBHelper", "开始解析:${txtFile?.name}")
@ -332,28 +332,28 @@ class ImportOMDBHelper @AssistedInject constructor(
}
}
//交限增加相同LinkIn与LinkOut过滤原则
if (renderEntity.code == DataCodeEnum.OMDB_RESTRICTION.code) {
if (renderEntity.properties.containsKey("linkIn") && renderEntity.properties.containsKey(
"linkOut"
)
) {
var linkIn = renderEntity.properties["linkIn"]
var linkOut = renderEntity.properties["linkOut"]
if (linkIn != null && linkOut != null) {
var checkMsg = "$linkIn$linkOut"
if (resHashMap.containsKey(checkMsg)) {
Log.e(
"qj",
"${renderEntity.name}==过滤交限linkin与linkout相同且存在多条数据"
)
continue
} else {
resHashMap.put(checkMsg, renderEntity)
}
}
}
}
// //交限增加相同LinkIn与LinkOut过滤原则
// if (renderEntity.code == DataCodeEnum.OMDB_RESTRICTION.code) {
// if (renderEntity.properties.containsKey("linkIn") && renderEntity.properties.containsKey(
// "linkOut"
// )
// ) {
// var linkIn = renderEntity.properties["linkIn"]
// var linkOut = renderEntity.properties["linkOut"]
// if (linkIn != null && linkOut != null) {
// var checkMsg = "$linkIn$linkOut"
// if (resHashMap.containsKey(checkMsg)) {
// Log.e(
// "qj",
// "${renderEntity.name}==过滤交限linkin与linkout相同且存在多条数据"
// )
// continue
// } else {
// resHashMap.put(checkMsg, renderEntity)
// }
// }
// }
// }
//遍历判断只显示与任务Link相关的任务数据
if (currentConfig.checkLinkId) {
@ -619,17 +619,17 @@ class ImportOMDBHelper @AssistedInject constructor(
renderEntity.properties["startTime"] = "null"
}
}
listResult.add(renderEntity)
// listResult.add(renderEntity)
realm.insert(renderEntity)
}
}
}
}
// 如果当前解析的是OMDB_RD_LINK数据将其缓存在预处理类中以便后续处理其他要素时使用
if (currentConfig.table == "OMDB_RD_LINK") {
importConfig.preProcess.cacheRdLink =
listResult.associateBy { it.properties["linkPid"] }
}
// // 如果当前解析的是OMDB_RD_LINK数据将其缓存在预处理类中以便后续处理其他要素时使用
// if (currentConfig.table == "OMDB_RD_LINK") {
// importConfig.preProcess.cacheRdLink =
// listResult.associateBy { it.properties["linkPid"] }
// }
realm.commitTransaction()
// 1个文件发送一次flow流
emit("${++processIndex}/${tableNum}")
@ -637,8 +637,6 @@ class ImportOMDBHelper @AssistedInject constructor(
} catch (e: Exception) {
realm.cancelTransaction()
throw e
} finally {
realm.close()
}
}
emit("finish")

View File

@ -20,23 +20,23 @@ class ImportPreProcess {
val defaultTranslateDistance = 3.0
val testFlag:Boolean = true
fun checkCircleRoad(renderEntity: RenderEntity): Boolean {
val linkInId = renderEntity.properties["linkIn"]
val linkOutId = renderEntity.properties["linkOut"]
// 根据linkIn和linkOut获取对应的link数据
val linkInEntity = cacheRdLink[linkInId]
val linkOutEntity = cacheRdLink[linkOutId]
Log.d(
"checkCircleRoad",
"LinkInEntity: ${linkInId}- ${linkInEntity?.properties?.get("snodePid")}LinkOutEntity: ${linkOutId}- ${
linkOutEntity?.properties?.get("enodePid")
}"
)
// 查询linkIn的sNode和linkOut的eNode是否相同如果相同认为数据是环形路口返回false
if (linkInEntity != null && linkOutEntity != null) {
if (linkInEntity.properties["snodePid"] == linkOutEntity.properties["enodePid"] || linkInEntity.properties["enodePid"] == linkOutEntity.properties["snodePid"] || linkInEntity.properties["snodePid"] == linkOutEntity.properties["snodePid"] || linkInEntity.properties["enodePid"] == linkOutEntity.properties["enodePid"]) {
return false
}
}
// val linkInId = renderEntity.properties["linkIn"]
// val linkOutId = renderEntity.properties["linkOut"]
// // 根据linkIn和linkOut获取对应的link数据
// val linkInEntity = cacheRdLink[linkInId]
// val linkOutEntity = cacheRdLink[linkOutId]
// Log.d(
// "checkCircleRoad",
// "LinkInEntity: ${linkInId}- ${linkInEntity?.properties?.get("snodePid")}LinkOutEntity: ${linkOutId}- ${
// linkOutEntity?.properties?.get("enodePid")
// }"
// )
// // 查询linkIn的sNode和linkOut的eNode是否相同如果相同认为数据是环形路口返回false
// if (linkInEntity != null && linkOutEntity != null) {
// if (linkInEntity.properties["snodePid"] == linkOutEntity.properties["enodePid"] || linkInEntity.properties["enodePid"] == linkOutEntity.properties["snodePid"] || linkInEntity.properties["snodePid"] == linkOutEntity.properties["snodePid"] || linkInEntity.properties["enodePid"] == linkOutEntity.properties["enodePid"]) {
// return false
// }
// }
return true
}