jdaugherty commented on code in PR #15122:
URL: https://github.com/apache/grails-core/pull/15122#discussion_r2426911227
##########
grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/events/AutoTimestampEventListener.java:
##########
@@ -148,10 +150,25 @@ private void initializeIfNecessary(PersistentEntity
entity, String name) {
public boolean beforeUpdate(PersistentEntity entity, EntityAccess ea) {
Set<String> props = getLastUpdatedPropertyNames(entity.getName());
if (props != null) {
+ Object entityObject = ea.getEntity();
+ boolean isDirtyCheckable = entityObject instanceof DirtyCheckable;
+
+ // For dirty-checking datastores (e.g., MongoDB), only set
autotimestamp if entity has dirty properties
+ if (isDirtyCheckable) {
+ List<String> dirtyPropertyNames = ((DirtyCheckable)
entityObject).listDirtyPropertyNames();
+ if (dirtyPropertyNames.isEmpty()) {
+ return true;
+ }
+ }
+
for (String prop : props) {
Class<?> lastUpdateType = ea.getPropertyType(prop);
Object timestamp =
timestampProvider.createTimestamp(lastUpdateType);
ea.setProperty(prop, timestamp);
+ // Mark property as dirty for datastores that use dirty
checking (e.g., MongoDB)
Review Comment:
I understand this is a mongo specific, but hibernate does have dirty
checking and works. What makes hibernate different here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]