Skip to content

Commit

Permalink
Revert "feat: improve DB query performance"
Browse files Browse the repository at this point in the history
This reverts commit 56a4b42.

reverting for now due to: #813
  • Loading branch information
peterhaochen47 committed Nov 11, 2024
1 parent 873bc6d commit 34afece
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 26 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public CredentialDataService(final CredentialRepository credentialRepository, fi
}

public Credential find(final String name) {
return credentialRepository.findOneByNameLowercase(name.toLowerCase());
return credentialRepository.findOneByNameIgnoreCase(name);
}

public Credential findByUUID(final UUID uuid) {
Expand All @@ -37,7 +37,7 @@ public Credential save(final Credential credential) {
public boolean delete(final String credentialName) {
final Credential cred = this.find(credentialName);
auditRecord.setResource(cred);
return credentialRepository.deleteByNameLowercase(credentialName.toLowerCase()) > 0;
return credentialRepository.deleteByNameIgnoreCase(credentialName) > 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class Credential : AuditableCredential {
}
}

@Column(name = "name_lowercase", nullable = false, insertable = false)
var nameLowercase: String? = null

@Column(unique = true, nullable = false)
var checksum: String? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import java.util.UUID

interface CredentialRepository : JpaRepository<Credential?, UUID?> {
@Transactional
fun deleteByNameLowercase(name: String?): Long
fun deleteByNameIgnoreCase(name: String?): Long

fun findOneByUuid(uuid: UUID?): Credential?

@Query(
value = "select credential.uuid, credential.name, credential.name_lowercase, credential.checksum from certificate_credential " +
value = "select credential.uuid, credential.name, credential.checksum from certificate_credential " +
"left join credential_version on certificate_credential.uuid = credential_version.uuid " +
"join credential on credential.uuid = credential_version.credential_uuid " +
"where credential.uuid = ?1",
nativeQuery = true,
)
fun findCertificateByUuid(uuid: UUID?): Credential?

fun findOneByNameLowercase(name: String?): Credential?
fun findOneByNameIgnoreCase(name: String?): Credential?

@Query(
value = "select credential.uuid, credential.name, credential.name_lowercase, credential.checksum from certificate_credential " +
value = "select credential.uuid, credential.name, credential.checksum from certificate_credential " +
"left join credential_version on certificate_credential.uuid = credential_version.uuid " +
"join credential on credential.uuid = credential_version.credential_uuid " +
"group by credential.uuid",
Expand All @@ -33,7 +33,7 @@ interface CredentialRepository : JpaRepository<Credential?, UUID?> {
fun findAllCertificates(): List<Credential>

@Query(
value = "select credential.uuid, credential.name, credential.name_lowercase, credential.checksum from certificate_credential " +
value = "select credential.uuid, credential.name, credential.checksum from certificate_credential " +
"left join credential_version on certificate_credential.uuid = credential_version.uuid " +
"join credential on credential.uuid = credential_version.credential_uuid " +
"where credential.name = ?1 limit 1 ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ constructor(
(select version_created_at, credential_uuid from credential_version LEFT OUTER JOIN
certificate_credential on credential_version.uuid = certificate_credential.uuid
WHERE (transitional is false or transitional IS NULL)
and credential_uuid in (select uuid from credential where name_lowercase like ?))
and credential_uuid in (select uuid from credential where lower(name) like ?))
as credential_version
group by credential_uuid ) as credential_version
inner join
(select * from credential where name_lowercase like ? )
(select * from credential where lower(name) like ? )
as name on credential_version.credential_uuid = name.uuid
order by version_created_at desc
""".trimMargin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CredentialDataServiceTest {
credentialRepository.save(credential)
MatcherAssert.assertThat(credentialRepository.count(), IsEqual.equalTo(1L))
MatcherAssert.assertThat(
credentialRepository.findOneByNameLowercase(CREDENTIAL_NAME.lowercase())!!.name,
credentialRepository.findOneByNameIgnoreCase(CREDENTIAL_NAME)!!.name,
IsEqual.equalTo(CREDENTIAL_NAME),
)
}
Expand Down

0 comments on commit 34afece

Please sign in to comment.