From bf7d963296cb0c6327df493907b47252fffe801f Mon Sep 17 00:00:00 2001 From: godotg Date: Mon, 24 Jun 2024 17:55:08 +0800 Subject: [PATCH] feat[orm]: persist the entity of the specified key --- .../java/com/zfoo/orm/cache/EntityCache.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/orm/src/main/java/com/zfoo/orm/cache/EntityCache.java b/orm/src/main/java/com/zfoo/orm/cache/EntityCache.java index 04827195..bc8aacfc 100644 --- a/orm/src/main/java/com/zfoo/orm/cache/EntityCache.java +++ b/orm/src/main/java/com/zfoo/orm/cache/EntityCache.java @@ -233,7 +233,17 @@ public class EntityCache, E extends IEntity> imple if (pnode == null) { return; } - updateUnsafeNow(pnode.getEntity()); + @SuppressWarnings("unchecked") + var entityClass = (Class) entityDef.getClazz(); + if (pnode.getModifiedTime() == pnode.getWriteToDbTime()) { + return; + } + var currentTime = TimeUtils.currentTimeMillis(); + pnode.setWriteToDbTime(currentTime); + pnode.setModifiedTime(currentTime); + var updateList = new ArrayList(); + updateList.add(pnode.getEntity()); + doPersist(updateList, entityClass); } // 游戏中80%都是执行更新的操作,这样做会极大的提高更新速度 @@ -256,6 +266,10 @@ public class EntityCache, E extends IEntity> imple } }); + doPersist(updateList, entityClass); + } + + private void doPersist(List updateList, Class entityClass) { // 执行更新 if (updateList.isEmpty()) { return;