Some performance improvement
parent
3463bb7f4d
commit
51a639422a
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@librecms/ccm-cms",
|
||||
"version": "7.0.0-SNAPSHOT.2023-03-21T165148",
|
||||
"version": "7.0.0-SNAPSHOT.2023-03-23T131710",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@librecms/ccm-cms",
|
||||
"version": "7.0.0-SNAPSHOT.2023-03-21T165148",
|
||||
"version": "7.0.0-SNAPSHOT.2023-03-23T131710",
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"@tiptap/core": "^2.0.0-beta.127",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@librecms/ccm-cms",
|
||||
"version": "7.0.0-SNAPSHOT.2023-03-21T165148",
|
||||
"version": "7.0.0-SNAPSHOT.2023-03-23T131710",
|
||||
"description": "JavaScript stuff for ccm-cms",
|
||||
"main": "target/generated-resources/assets/@content-sections/cms-admin.js",
|
||||
"types": "target/generated-resources/assets/@content-sections/cms-admin.d.ts",
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ import org.librecms.lifecycle.LifecycleDefinition;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.NamedNativeQueries;
|
||||
import javax.persistence.NamedNativeQuery;
|
||||
import javax.persistence.OrderBy;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
|
|
@ -118,6 +120,48 @@ import static org.librecms.CmsConstants.*;
|
|||
+ " OR p.object = :rootAssetsFolder) "
|
||||
+ "AND p.grantee = :role")
|
||||
})
|
||||
@NamedNativeQueries({
|
||||
@NamedNativeQuery(
|
||||
name = "ContentSection.countAssetSubFoldersOfRootFolder",
|
||||
query = "SELECT COUNT(*) "
|
||||
+ "FROM ccm_core.categories "
|
||||
+ "WHERE parent_category_id = ("
|
||||
+ " SELECT root_assets_folder_id "
|
||||
+ " FROM ccm_cms.content_sections "
|
||||
+ " WHERE object_id = :sectionId"
|
||||
+ ")"
|
||||
),
|
||||
@NamedNativeQuery(
|
||||
name = "ContentSection.countDocumentSubFoldersOfRootFolder",
|
||||
query = "SELECT COUNT(*) "
|
||||
+ "FROM ccm_core.categories "
|
||||
+ "WHERE parent_category_id = ("
|
||||
+ " SELECT root_documents_folder_id "
|
||||
+ " FROM ccm_cms.content_sections "
|
||||
+ " WHERE object_id = :sectionId"
|
||||
+ ")"
|
||||
),
|
||||
@NamedNativeQuery(
|
||||
name = "ContentSection.countObjectsInRootAssetsFolder",
|
||||
query = "SELECT COUNT(*) "
|
||||
+ "FROM ccm_core.categorizations "
|
||||
+ "WHERE category_id = ("
|
||||
+ " SELECT root_assets_folder_id "
|
||||
+ " FROM ccm_cms.content_sections "
|
||||
+ " WHERE object_id = :sectionId"
|
||||
+ ");"
|
||||
),
|
||||
@NamedNativeQuery(
|
||||
name = "ContentSection.countObjectsInRootDocumentsFolder",
|
||||
query = "SELECT COUNT(*) "
|
||||
+ "FROM ccm_core.categorizations "
|
||||
+ "WHERE category_id = ("
|
||||
+ " SELECT root_documents_folder_id "
|
||||
+ " FROM ccm_cms.content_sections "
|
||||
+ " WHERE object_id = :sectionId"
|
||||
+ ");"
|
||||
)
|
||||
})
|
||||
//@ApplicationType(
|
||||
// name = CONTENT_SECTION_APP_TYPE,
|
||||
// descBundle = "org.librecms.contentsection.ContentSectionResources",
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ import org.libreccm.core.CoreConstants;
|
|||
import org.libreccm.security.AuthorizationRequired;
|
||||
import org.libreccm.security.RequiresPrivilege;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -72,8 +74,10 @@ public class ContentSectionRepository
|
|||
}
|
||||
|
||||
final TypedQuery<ContentSection> query = getEntityManager()
|
||||
.createNamedQuery("ContentSection.findByLabel",
|
||||
ContentSection.class);
|
||||
.createNamedQuery(
|
||||
"ContentSection.findByLabel",
|
||||
ContentSection.class
|
||||
);
|
||||
query.setParameter("label", label);
|
||||
|
||||
try {
|
||||
|
|
@ -83,6 +87,60 @@ public class ContentSectionRepository
|
|||
}
|
||||
}
|
||||
|
||||
public long countAssetSubFoldersOfRootFolder(final ContentSection section) {
|
||||
Objects.requireNonNull(section);
|
||||
|
||||
final BigInteger result = (BigInteger) getEntityManager()
|
||||
.createNamedQuery(
|
||||
"ContentSection.countAssetSubFoldersOfRootFolder"
|
||||
)
|
||||
.setParameter("sectionId", section.getObjectId())
|
||||
.getSingleResult();
|
||||
|
||||
return result.longValue();
|
||||
}
|
||||
|
||||
public long countDocumentSubFoldersOfRootFolder(
|
||||
final ContentSection section
|
||||
) {
|
||||
Objects.requireNonNull(section);
|
||||
|
||||
final BigInteger result = (BigInteger) getEntityManager()
|
||||
.createNamedQuery(
|
||||
"ContentSection.countDocumentSubFoldersOfRootFolder"
|
||||
)
|
||||
.setParameter("sectionId", section.getObjectId())
|
||||
.getSingleResult();
|
||||
|
||||
return result.longValue();
|
||||
}
|
||||
|
||||
public long countObjectsInRootAssetFolder(final ContentSection section) {
|
||||
Objects.requireNonNull(section);
|
||||
|
||||
final BigInteger result = (BigInteger) getEntityManager()
|
||||
.createNamedQuery(
|
||||
"ContentSection.countObjectsInRootAssetsFolder"
|
||||
)
|
||||
.setParameter("sectionId", section.getObjectId())
|
||||
.getSingleResult();
|
||||
|
||||
return result.longValue();
|
||||
}
|
||||
|
||||
public long countObjectsInRootDocumentsFolder(final ContentSection section) {
|
||||
Objects.requireNonNull(section);
|
||||
|
||||
final BigInteger result = (BigInteger) getEntityManager()
|
||||
.createNamedQuery(
|
||||
"ContentSection.countObjectsInRootDocumentsFolder"
|
||||
)
|
||||
.setParameter("sectionId", section.getObjectId())
|
||||
.getSingleResult();
|
||||
|
||||
return result.longValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ContentSection> getEntityClass() {
|
||||
return ContentSection.class;
|
||||
|
|
|
|||
|
|
@ -244,13 +244,29 @@ public class ContentSectionsController {
|
|||
* {@code false} is not.
|
||||
*/
|
||||
protected boolean canDelete(final ContentSection section) {
|
||||
final Folder rootAssetsFolder = section.getRootAssetsFolder();
|
||||
final Folder rootDocumentsFolder = section.getRootDocumentsFolder();
|
||||
final long rootAssetFolders = sectionRepo
|
||||
.countAssetSubFoldersOfRootFolder(section);
|
||||
final long rootDocumentFolders = sectionRepo
|
||||
.countDocumentSubFoldersOfRootFolder(section);
|
||||
final long assetsInRootFolder = sectionRepo
|
||||
.countObjectsInRootAssetFolder(section);
|
||||
final long documentsInRootFolder = sectionRepo
|
||||
.countObjectsInRootDocumentsFolder(section);
|
||||
|
||||
return rootAssetsFolder.getSubFolders().isEmpty()
|
||||
&& rootAssetsFolder.getObjects().isEmpty()
|
||||
&& rootDocumentsFolder.getSubFolders().isEmpty()
|
||||
&& rootDocumentsFolder.getObjects().isEmpty();
|
||||
final long result = rootAssetFolders
|
||||
+ rootDocumentFolders
|
||||
+ assetsInRootFolder
|
||||
+ documentsInRootFolder;
|
||||
|
||||
return result == 0;
|
||||
|
||||
// final Folder rootAssetsFolder = section.getRootAssetsFolder();
|
||||
// final Folder rootDocumentsFolder = section.getRootDocumentsFolder();
|
||||
//
|
||||
// return rootAssetsFolder.getSubFolders().isEmpty()
|
||||
// && rootAssetsFolder.getObjects().isEmpty()
|
||||
// && rootDocumentsFolder.getSubFolders().isEmpty()
|
||||
// && rootDocumentsFolder.getObjects().isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,20 @@ public class ContentSectionsTableRow implements
|
|||
*/
|
||||
private boolean deletable;
|
||||
|
||||
public ContentSectionsTableRow() {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
public ContentSectionsTableRow(
|
||||
final long sectionId,
|
||||
final String label,
|
||||
final boolean deletable
|
||||
) {
|
||||
this.sectionId = sectionId;
|
||||
this.label = label;
|
||||
this.deletable = deletable;
|
||||
}
|
||||
|
||||
public long getSectionId() {
|
||||
return sectionId;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue