Skip to content

Commit

Permalink
Legger til indeks for henholdsvis opplysninger_id og opplysing_id i o…
Browse files Browse the repository at this point in the history
…pplysninger_opplysning tabellen. Lager transaksjon per kandidat vi sletter.

Co-authored-by: Richard André Martinsen <[email protected]>
  • Loading branch information
geiralund and richardmartinsen committed Jan 14, 2025
1 parent 2a08d4d commit 3f8ba2a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ internal object SlettFjernetOpplysninger {
period = 15.minutes.inWholeMilliseconds,
action = {
try {
if (System.getenv("NAIS_CLUSTER_NAME") == "skrudd-av") {
vaktmesterRepository.slettOpplysninger(antall = 10)
if (System.getenv("NAIS_CLUSTER_NAME") == "DEV-GCP") {
vaktmesterRepository.slettOpplysninger(antall = 1)
} else {
logger.info { "Sletting av fjernet opplysninger er skrudd av" }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.nav.dagpenger.behandling.mediator.repository

import kotliquery.Session
import kotliquery.TransactionalSession
import kotliquery.queryOf
import kotliquery.sessionOf
import kotliquery.using
Expand All @@ -21,9 +20,10 @@ internal class VaktmesterPostgresRepo {
fun slettOpplysninger(antall: Int = 1): List<UUID> {
val slettet = mutableListOf<UUID>()
using(sessionOf(dataSource)) { session ->
session.transaction { tx ->
tx.medLås(låsenøkkel) {
hentAlleOpplysningerSomErFjernet(tx, antall).forEach { kandidat ->
val kandidater = hentAlleOpplysningerSomErFjernet(session, antall)
kandidater.forEach { kandidat ->
session.transaction { tx ->
tx.medLås(låsenøkkel) {
withLoggingContext(
"behandlingId" to kandidat.behandlingId.toString(),
"opplysningerId" to kandidat.opplysningerId.toString(),
Expand All @@ -42,7 +42,7 @@ internal class VaktmesterPostgresRepo {
}
slettet.add(opplysningId)
}
logger.info { "Slettet ${kandidat.opplysninger().size} opplysninger " }
logger.info { "Slettet ${kandidat.opplysninger().size} opplysninger" }
}
}
}
Expand All @@ -64,10 +64,10 @@ internal class VaktmesterPostgresRepo {
}

private fun hentAlleOpplysningerSomErFjernet(
tx: TransactionalSession,
session: Session,
antall: Int,
): List<Kandidater> {
val kandidater = hentOpplysningerIder(tx, antall)
val kandidater = hentOpplysningerIder(session, antall)

//language=PostgreSQL
val query =
Expand All @@ -81,7 +81,7 @@ internal class VaktmesterPostgresRepo {

val opplysninger =
kandidater.onEach { kandidat ->
tx.run(
session.run(
queryOf(
query,
mapOf("opplysninger_id" to kandidat.opplysningerId),
Expand All @@ -97,7 +97,7 @@ internal class VaktmesterPostgresRepo {
}

private fun hentOpplysningerIder(
tx: TransactionalSession,
session: Session,
antall: Int,
): List<Kandidater> {
//language=PostgreSQL
Expand All @@ -112,7 +112,7 @@ internal class VaktmesterPostgresRepo {
""".trimIndent()

val opplysningerIder =
tx.run(
session.run(
queryOf(
test,
mapOf("antall" to antall),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE INDEX idx_opplysninger_opplysning_id ON opplysninger_opplysning (opplysning_id);
CREATE INDEX idx_opplysninger_opplysninger_id ON opplysninger_opplysning (opplysninger_id);
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PostgresMigrationTest {
fun `Migration scripts are applied successfully`() {
withCleanDb {
val migrations = runMigration()
migrations shouldBeExactly 34
migrations shouldBeExactly 35
}
}
}

0 comments on commit 3f8ba2a

Please sign in to comment.