Skip to content

Commit

Permalink
Patch/performance fixes (#620)
Browse files Browse the repository at this point in the history
* remove join to base content as lazy is ignored when join fetch is specified

* add activeContentVersions RO property, add asString argument to getActiveContet to pull criteria projection of only content string

* doc and formatting updates

* fix conditional
  • Loading branch information
jclausen authored Jan 13, 2025
1 parent 19b3481 commit 08df5e9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
68 changes: 35 additions & 33 deletions modules/contentbox/models/content/BaseContent.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,28 @@ component
singularName="contentVersion"
fieldtype ="one-to-many"
type ="array"
lazy ="true"
lazy ="extra"
batchsize ="25"
cfc ="contentbox.models.content.ContentVersion"
orderby ="version desc"
fkcolumn ="FK_contentID"
inverse ="true"
cascade ="all-delete-orphan";

property
name ="activeContentVersions"
singularName="activeContentVersion"
fieldtype ="one-to-many"
type ="array"
lazy ="extra"
where ="isActive = 1"
batchsize ="2"
cfc ="contentbox.models.content.ContentVersion"
orderby ="version desc"
fkcolumn ="FK_contentID"
insert =false
update =false;

// M20 -> Parent Page loaded as a proxy
property
name ="parent"
Expand Down Expand Up @@ -1120,34 +1134,32 @@ component
* Retrieves the latest content string from the latest version un-translated
*/
string function getContent(){
return getActiveContent().getContent();
return getActiveContent( true );
}

/**
* Get the latest active version object, empty new one if none assigned
*
* @asString Default false. When provided as true, a projection list query to retrieve only the string content will be executed
*/
ContentVersion function getActiveContent(){
any function getActiveContent( asString = false ){
// If we don't have any versions, send back a new one
if ( !hasContentVersion() ) {
return variables.contentVersionService.new();
}

// Load up the active content if not set yet
if ( isNull( variables.activeContent ) ) {
// Iterate and find, they are sorted descending, so it should be quick, unless we don't have one and that's ok.
for ( var thisVersion in variables.contentVersions ) {
if ( thisVersion.getIsActive() ) {
variables.activeContent = thisVersion;
break;
}
}
// We didn't find one, something is out of sync, return just an empty version
if ( isNull( variables.activeContent ) ) {
return variables.contentVersionService.new();
}
if ( !hasActiveContentVersion() ) {
return arguments.asString ? "" : variables.contentVersionService.new();
} else if ( arguments.asString ) {
var activeContentStruct = contentVersionService
.newCriteria()
.isEq( "relatedContent.contentID", getContentID() )
.isEq( "isActive", javacast( "boolean", true ) )
.withProjections( property = "content" )
.asStruct()
.order( "version", "desc" )
.list( max = 1 )
.first();
return activeContentStruct[ "content" ];
} else {
return getActiveContentVersions().first();
}

return variables.activeContent;
}

/**
Expand All @@ -1164,17 +1176,7 @@ component
* Verify if this content object has an active version with content
*/
boolean function hasActiveContent(){
// If we are not persisted, then no exit out.
if ( !hasContentVersion() || !isLoaded() ) {
return false;
}
// Iterate and find, they are sorted descending, so it should be quick, unless we don't have one and that's ok.
for ( var thisVersion in variables.contentVersions ) {
if ( thisVersion.getIsActive() ) {
return true;
}
}
return false;
return isLoaded() && hasActiveContentVersion();
}

/**
Expand Down
1 change: 0 additions & 1 deletion modules/contentbox/models/content/ContentVersion.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ component
fieldtype="many-to-one"
fkcolumn ="FK_contentID"
lazy ="true"
fetch ="join"
index ="idx_contentVersions";

/* *********************************************************************
Expand Down

0 comments on commit 08df5e9

Please sign in to comment.