Some performance improvement

deploy_packages_to_gitea
Jens Pelzetter 2023-03-23 14:21:08 +01:00
parent 3463bb7f4d
commit 51a639422a
6 changed files with 144 additions and 12 deletions

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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;
@ -48,7 +50,7 @@ public class ContentSectionRepository
.createNamedQuery("ContentSection.findAll", ContentSection.class)
.getResultList();
}
public Optional<ContentSection> findByUuid(final String uuid) {
try {
return Optional.of(
@ -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;

View File

@ -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();
}
}

View File

@ -48,6 +48,20 @@ public class ContentSectionsTableRow implements
* Is the section empty and can be deleted?
*/
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;