Some performance improvement
parent
3463bb7f4d
commit
51a639422a
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@librecms/ccm-cms",
|
"name": "@librecms/ccm-cms",
|
||||||
"version": "7.0.0-SNAPSHOT.2023-03-21T165148",
|
"version": "7.0.0-SNAPSHOT.2023-03-23T131710",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@librecms/ccm-cms",
|
"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",
|
"license": "LGPL-3.0-or-later",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tiptap/core": "^2.0.0-beta.127",
|
"@tiptap/core": "^2.0.0-beta.127",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@librecms/ccm-cms",
|
"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",
|
"description": "JavaScript stuff for ccm-cms",
|
||||||
"main": "target/generated-resources/assets/@content-sections/cms-admin.js",
|
"main": "target/generated-resources/assets/@content-sections/cms-admin.js",
|
||||||
"types": "target/generated-resources/assets/@content-sections/cms-admin.d.ts",
|
"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.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.persistence.NamedNativeQueries;
|
||||||
|
import javax.persistence.NamedNativeQuery;
|
||||||
import javax.persistence.OrderBy;
|
import javax.persistence.OrderBy;
|
||||||
|
|
||||||
import static org.librecms.CmsConstants.*;
|
import static org.librecms.CmsConstants.*;
|
||||||
|
|
@ -118,6 +120,48 @@ import static org.librecms.CmsConstants.*;
|
||||||
+ " OR p.object = :rootAssetsFolder) "
|
+ " OR p.object = :rootAssetsFolder) "
|
||||||
+ "AND p.grantee = :role")
|
+ "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(
|
//@ApplicationType(
|
||||||
// name = CONTENT_SECTION_APP_TYPE,
|
// name = CONTENT_SECTION_APP_TYPE,
|
||||||
// descBundle = "org.librecms.contentsection.ContentSectionResources",
|
// descBundle = "org.librecms.contentsection.ContentSectionResources",
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,9 @@ import org.libreccm.core.CoreConstants;
|
||||||
import org.libreccm.security.AuthorizationRequired;
|
import org.libreccm.security.AuthorizationRequired;
|
||||||
import org.libreccm.security.RequiresPrivilege;
|
import org.libreccm.security.RequiresPrivilege;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -48,7 +50,7 @@ public class ContentSectionRepository
|
||||||
.createNamedQuery("ContentSection.findAll", ContentSection.class)
|
.createNamedQuery("ContentSection.findAll", ContentSection.class)
|
||||||
.getResultList();
|
.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<ContentSection> findByUuid(final String uuid) {
|
public Optional<ContentSection> findByUuid(final String uuid) {
|
||||||
try {
|
try {
|
||||||
return Optional.of(
|
return Optional.of(
|
||||||
|
|
@ -72,8 +74,10 @@ public class ContentSectionRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
final TypedQuery<ContentSection> query = getEntityManager()
|
final TypedQuery<ContentSection> query = getEntityManager()
|
||||||
.createNamedQuery("ContentSection.findByLabel",
|
.createNamedQuery(
|
||||||
ContentSection.class);
|
"ContentSection.findByLabel",
|
||||||
|
ContentSection.class
|
||||||
|
);
|
||||||
query.setParameter("label", label);
|
query.setParameter("label", label);
|
||||||
|
|
||||||
try {
|
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
|
@Override
|
||||||
public Class<ContentSection> getEntityClass() {
|
public Class<ContentSection> getEntityClass() {
|
||||||
return ContentSection.class;
|
return ContentSection.class;
|
||||||
|
|
|
||||||
|
|
@ -244,13 +244,29 @@ public class ContentSectionsController {
|
||||||
* {@code false} is not.
|
* {@code false} is not.
|
||||||
*/
|
*/
|
||||||
protected boolean canDelete(final ContentSection section) {
|
protected boolean canDelete(final ContentSection section) {
|
||||||
final Folder rootAssetsFolder = section.getRootAssetsFolder();
|
final long rootAssetFolders = sectionRepo
|
||||||
final Folder rootDocumentsFolder = section.getRootDocumentsFolder();
|
.countAssetSubFoldersOfRootFolder(section);
|
||||||
|
final long rootDocumentFolders = sectionRepo
|
||||||
|
.countDocumentSubFoldersOfRootFolder(section);
|
||||||
|
final long assetsInRootFolder = sectionRepo
|
||||||
|
.countObjectsInRootAssetFolder(section);
|
||||||
|
final long documentsInRootFolder = sectionRepo
|
||||||
|
.countObjectsInRootDocumentsFolder(section);
|
||||||
|
|
||||||
return rootAssetsFolder.getSubFolders().isEmpty()
|
final long result = rootAssetFolders
|
||||||
&& rootAssetsFolder.getObjects().isEmpty()
|
+ rootDocumentFolders
|
||||||
&& rootDocumentsFolder.getSubFolders().isEmpty()
|
+ assetsInRootFolder
|
||||||
&& rootDocumentsFolder.getObjects().isEmpty();
|
+ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,20 @@ public class ContentSectionsTableRow implements
|
||||||
* Is the section empty and can be deleted?
|
* Is the section empty and can be deleted?
|
||||||
*/
|
*/
|
||||||
private boolean deletable;
|
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() {
|
public long getSectionId() {
|
||||||
return sectionId;
|
return sectionId;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue