Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing indexes for FKs (first part) #2600

Merged
merged 8 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend/data/src/main/kotlin/io/tolgee/model/ApiKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.FetchType
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import jakarta.persistence.Temporal
Expand All @@ -23,6 +24,10 @@ import java.util.*
UniqueConstraint(columnNames = ["keyHash"], name = "api_key_hash_unique"),
UniqueConstraint(columnNames = ["key"], name = "api_key_unique"),
],
indexes = [
Index(columnList = "project_id"),
Index(columnList = "user_account_id"),
],
)
class ApiKey(
@Column(updatable = false, insertable = false, nullable = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package io.tolgee.model

import jakarta.persistence.Entity
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToOne
import jakarta.persistence.Table
import org.hibernate.annotations.ColumnDefault

@Entity
@Table(
indexes = [
Index(columnList = "project_id"),
],
)
class AutoTranslationConfig : StandardAuditModel() {
@ManyToOne
lateinit var project: Project
Expand Down
4 changes: 4 additions & 0 deletions backend/data/src/main/kotlin/io/tolgee/model/Language.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ import java.util.*
columnList = "tag, project_id",
name = "index_tag_project",
),
Index(
columnList = "project_id",
name = "index_project_id",
),
],
)
@ActivityLoggedEntity
Expand Down
8 changes: 8 additions & 0 deletions backend/data/src/main/kotlin/io/tolgee/model/Permission.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,27 @@ import jakarta.persistence.FetchType
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.Index
import jakarta.persistence.JoinColumn
import jakarta.persistence.JoinTable
import jakarta.persistence.ManyToMany
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToOne
import jakarta.persistence.PrePersist
import jakarta.persistence.PreUpdate
import jakarta.persistence.Table
import org.hibernate.annotations.Parameter
import org.hibernate.annotations.Type

@Suppress("LeakingThis")
@Entity
@EntityListeners(Permission.Companion.PermissionListeners::class)
@Table(
indexes = [
Index(columnList = "user_id"),
Index(columnList = "project_id"),
],
)
class Permission(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
12 changes: 11 additions & 1 deletion backend/data/src/main/kotlin/io/tolgee/model/Project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ import java.util.*
import kotlin.jvm.Transient

@Entity
@Table(uniqueConstraints = [UniqueConstraint(columnNames = ["address_part"], name = "project_address_part_unique")])
@Table(
uniqueConstraints = [
UniqueConstraint(
columnNames = ["address_part"],
name = "project_address_part_unique",
),
],
indexes = [
Index(columnList = "organization_owner_id"),
],
)
@EntityListeners(Project.Companion.ProjectListener::class)
@ActivityLoggedEntity
class Project(
Expand Down
10 changes: 9 additions & 1 deletion backend/data/src/main/kotlin/io/tolgee/model/batch/BatchJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ import jakarta.persistence.Entity
import jakarta.persistence.EnumType.STRING
import jakarta.persistence.Enumerated
import jakarta.persistence.FetchType
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToOne
import jakarta.persistence.Table
import org.hibernate.annotations.Type
import java.util.*

@Entity
@Table(name = "tolgee_batch_job")
@Table(
name = "tolgee_batch_job",
indexes = [
Index(columnList = "project_id"),
Index(columnList = "author_id"),
Index(columnList = "debouncing_key"),
],
)
class BatchJob : StandardAuditModel(), IBatchJob {
@ManyToOne(fetch = FetchType.LAZY)
lateinit var project: Project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.FetchType
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToOne
import jakarta.persistence.Table
Expand All @@ -20,8 +21,9 @@ import java.util.*
@Table(
name = "tolgee_batch_job_chunk_execution",
indexes = [
jakarta.persistence.Index(columnList = "chunkNumber"),
jakarta.persistence.Index(columnList = "status"),
Index(columnList = "batch_job_id"),
Index(columnList = "chunkNumber"),
Index(columnList = "status"),
],
)
class BatchJobChunkExecution : StandardAuditModel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import jakarta.validation.constraints.Size
import org.hibernate.annotations.ColumnDefault

@Entity
@Table(
indexes = [
Index(columnList = "file_id"),
],
)
class ImportKey(
@field:NotBlank
@field:Size(max = 2000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import jakarta.validation.constraints.NotNull
import org.apache.commons.codec.digest.MurmurHash3
import org.hibernate.annotations.ColumnDefault
Expand All @@ -17,6 +19,14 @@ import java.nio.ByteBuffer
import java.util.*

@Entity
@Table(
indexes = [
Index(
name = "import_translation_language_id_id",
columnList = "language_id",
),
],
)
class ImportTranslation(
@Column(columnDefinition = "text")
var text: String?,
Expand Down
8 changes: 8 additions & 0 deletions backend/data/src/main/kotlin/io/tolgee/model/key/Key.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EntityListeners
import jakarta.persistence.FetchType
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToMany
import jakarta.persistence.OneToOne
import jakarta.persistence.PrePersist
import jakarta.persistence.PreRemove
import jakarta.persistence.Table
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size
Expand All @@ -38,6 +40,12 @@ import org.springframework.context.ApplicationEventPublisher
@ActivityReturnsExistence
@ActivityEntityDescribingPaths(["namespace"])
@EntityListeners(Key.Companion.KeyListeners::class)
@Table(
indexes = [
Index(columnList = "project_id"),
Index(columnList = "namespace_id"),
],
)
class Key(
@field:NotBlank
@field:Size(max = 2000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ import io.tolgee.model.UserAccount
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull

@Entity
@Table(
indexes = [
Index(columnList = "keyMeta_id"),
],
)
class KeyCodeReference(
@ManyToOne(optional = false)
override var keyMeta: KeyMeta,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ import io.tolgee.model.UserAccount
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull

@Entity
@Table(
indexes = [
Index(columnList = "key_meta_id"),
],
)
class KeyComment(
@ManyToOne(optional = false)
override var keyMeta: KeyMeta,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import jakarta.persistence.Entity
import jakarta.persistence.EntityListeners
import jakarta.persistence.Enumerated
import jakarta.persistence.FetchType
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToMany
import jakarta.persistence.PrePersist
Expand All @@ -34,6 +35,10 @@ import org.hibernate.annotations.ColumnDefault
name = "translation_key_language",
),
],
indexes = [
Index(columnList = "key_id"),
Index(columnList = "language_id"),
],
)
@ActivityLoggedEntity
@EntityListeners(Translation.Companion.UpdateStatsListener::class, Translation.Companion.StateListener::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ interface KeyRepository : JpaRepository<Key, Long> {
"""
from Language l
join l.translations t
where t.id in (select t.id from Key k join k.translations t where k.id = :keyId)
where t.key.id = :keyId
JanCizmar marked this conversation as resolved.
Show resolved Hide resolved
and l.project.id = :projectId
and t.state = io.tolgee.model.enums.TranslationState.DISABLED
order by l.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ interface LanguageRepository : JpaRepository<Language, Long> {
where l.project.id = :projectId and l.id in :languageIds and l.deletedAt is null
""",
)
fun findAllByProjectIdAndIdInOrderById(
fun findAllByProjectIdAndIds(
projectId: Long,
languageIds: List<Long>,
): List<Language>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ class KeyService(
languageIds: List<Long>,
key: Key,
): List<Language> {
val languages = languageRepository.findAllByProjectIdAndIdInOrderById(projectId, languageIds)
languages.map { language ->
val languages = languageRepository.findAllByProjectIdAndIds(projectId, languageIds)
languages.forEach { language ->
val translation = translationService.getOrCreate(key, language)
translation.clear()
translation.state = TranslationState.DISABLED
Expand Down
90 changes: 90 additions & 0 deletions backend/data/src/main/resources/db/changelog/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3558,4 +3558,94 @@
</column>
</addColumn>
</changeSet>
<changeSet author="anty (generated)" id="1729020991123-1">
<sql>
create index if not exists import_translation_language_id_id on import_translation (language_id);
</sql>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-1">
<createIndex indexName="IDX2i3yx2idx8unp1318an4ko9uh" tableName="api_key">
<column name="user_account_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-2">
<createIndex indexName="IDX36jc7xjy9os6gpk6a1itnc4oc" tableName="translation">
<column name="language_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-3">
<createIndex indexName="IDX3bevu8kvpirhwtua7bqny8mc5" tableName="tolgee_batch_job">
<column name="project_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-4">
<createIndex indexName="IDX3gv8wpf7vosi0kiky55etxxka" tableName="auto_translation_config">
<column name="project_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-5">
<createIndex indexName="IDX6p3mx8al2w4f7ltqiwf1j88fm" tableName="permission">
<column name="user_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-6">
<createIndex indexName="IDX8o82rss5686hnbidsbpe69jf6" tableName="key_comment">
<column name="key_meta_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-7">
<createIndex indexName="IDX8s40n0n4m3rcfo66vi8fl9b2f" tableName="tolgee_batch_job">
<column name="author_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-8">
<createIndex indexName="IDX9uwg4sei1gso5jc8l0fi5gt31" tableName="key">
<column name="project_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-9">
<createIndex indexName="IDXchpsdpcytt8o0nub8sw9ayx1k" tableName="permission">
<column name="project_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-10">
<createIndex indexName="IDXe67q4k71yrg8d5d91wlauwu7r" tableName="import_key">
<column name="file_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-11">
<createIndex indexName="IDXhhp7il8c4o1galygoy3exfii8" tableName="key_code_reference">
<column name="key_meta_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-12">
<createIndex indexName="IDXkrh888rhj0c4mm455al08el84" tableName="translation">
<column name="key_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-13">
<createIndex indexName="IDXr4bj1d6iqsmid4bevm9i3b555" tableName="key">
<column name="namespace_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-14">
<createIndex indexName="IDXs7dpucbxy0uf9xic0crc2a2uv" tableName="tolgee_batch_job_chunk_execution">
<column name="batch_job_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-15">
<createIndex indexName="IDXtedxl9xhocgey7ll6wh8lb945" tableName="project">
<column name="organization_owner_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-16">
<createIndex indexName="IDXterdfiw1uvbri2wn9kd0jl04v" tableName="api_key">
<column name="project_id"/>
</createIndex>
</changeSet>
<changeSet author="anty (generated)" id="1729173325348-17">
<createIndex indexName="index_project_id" tableName="language">
<column name="project_id"/>
</createIndex>
</changeSet>
</databaseChangeLog>
Loading