Skip to content

Commit 06cd2d8

Browse files
wezellclaude
andcommitted
perf(identifier): restrict stale-cache guard to UPDATE path in saveIdentifier()
The ContentTypeAPI lookup that resolves a missing base_type was running on every saveIdentifier() call regardless of whether it was an INSERT or UPDATE. INSERT callers always provide base_type (set in createNewIdentifier), so the guard was only ever needed for UPDATE — where a stale cached Identifier loaded before the backfill ran could write null back over a freshly populated value. Moving the guard inside the isIdentifier==true branch eliminates the API+DB call on all INSERT paths, making bulk operations (imports, publishing pipelines) that create many new identifiers unaffected during the migration window. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 09f112b commit 06cd2d8

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

dotCMS/src/main/java/com/dotmarketing/business/IdentifierFactoryImpl.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,23 @@ protected Identifier saveIdentifier(final Identifier id) throws DotDataException
521521
if (UtilMethods.isSet(id.getId())) {
522522
if (isIdentifier(id.getId())) {
523523
query = "UPDATE identifier set parent_path=?, asset_name=?, host_inode=?, asset_type=?, syspublish_date=?, sysexpire_date=?, owner=?, create_date=?, asset_subtype=?, base_type=? where id=?";
524+
// Guard against stale cached Identifiers (loaded before base_type was
525+
// denormalized) writing null back and temporarily undoing the backfill.
526+
// Only needed on UPDATE — INSERT callers must always supply base_type.
527+
if (id.getBaseType() == null && UtilMethods.isSet(id.getAssetSubType())) {
528+
final Integer resolvedBaseType = Try.of(() ->
529+
APILocator.getContentTypeAPI(APILocator.systemUser())
530+
.find(id.getAssetSubType())
531+
.baseType()
532+
.getType())
533+
.onFailure(e -> Logger.warn(IdentifierFactoryImpl.class,
534+
"Could not resolve base_type for asset_subtype=" + id.getAssetSubType()
535+
+ " on identifier=" + id.getId() + ": " + e.getMessage()))
536+
.getOrNull();
537+
if (resolvedBaseType != null) {
538+
id.setBaseType(resolvedBaseType);
539+
}
540+
}
524541
} else {
525542
query = "INSERT INTO identifier (parent_path,asset_name,host_inode,asset_type,syspublish_date,sysexpire_date,owner,create_date,asset_subtype,base_type,id) values (?,?,?,?,?,?,?,?,?,?,?)";
526543
}
@@ -529,23 +546,6 @@ protected Identifier saveIdentifier(final Identifier id) throws DotDataException
529546
query = "INSERT INTO identifier (parent_path,asset_name,host_inode,asset_type,syspublish_date,sysexpire_date,owner,create_date,asset_subtype,base_type,id) values (?,?,?,?,?,?,?,?,?,?,?)";
530547
}
531548

532-
// Guard against stale cached Identifiers (loaded before base_type was denormalized)
533-
// writing null back and temporarily undoing the backfill for this row.
534-
if (id.getBaseType() == null && UtilMethods.isSet(id.getAssetSubType())) {
535-
final Integer resolvedBaseType = Try.of(() ->
536-
APILocator.getContentTypeAPI(APILocator.systemUser())
537-
.find(id.getAssetSubType())
538-
.baseType()
539-
.getType())
540-
.onFailure(e -> Logger.warn(IdentifierFactoryImpl.class,
541-
"Could not resolve base_type for asset_subtype=" + id.getAssetSubType()
542-
+ " on identifier=" + id.getId() + ": " + e.getMessage()))
543-
.getOrNull();
544-
if (resolvedBaseType != null) {
545-
id.setBaseType(resolvedBaseType);
546-
}
547-
}
548-
549549
DotConnect dc = new DotConnect();
550550
dc.setSQL(query);
551551

0 commit comments

Comments
 (0)