Skip to content

Commit

Permalink
feat. optimalisere index på arena_events -> det mangler index på status
Browse files Browse the repository at this point in the history
Det mangler index på status på arena-events tabellen.
I tillegg så kan noen indexer fjernes fordi de ikke brukes lengre til oppslag.
  • Loading branch information
eirikv committed Dec 4, 2024
1 parent c5396c0 commit 26e18af
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import no.nav.tag.tiltaksgjennomforing.arena.models.event.ArenaEvent;
import no.nav.tag.tiltaksgjennomforing.arena.models.event.ArenaEventStatus;
import org.springframework.data.domain.Limit;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;
Expand All @@ -13,8 +13,20 @@ public interface ArenaEventRepository extends JpaRepository<ArenaEvent, UUID> {

Optional<ArenaEvent> findByArenaIdAndArenaTable(String arenaId, String arenaTable);

List<ArenaEvent> findByStatus(ArenaEventStatus status, Limit limit);
@Query("""
SELECT ae
FROM ArenaEvent ae
WHERE ae.status = :status
ORDER BY ae.status LIMIT 1000
""")
List<ArenaEvent> findByStatus(ArenaEventStatus status);

List<ArenaEvent> findByStatusAndArenaTable(ArenaEventStatus status, String arenaTable, Limit limit);
@Query("""
SELECT ae
FROM ArenaEvent ae
WHERE ae.status = :status AND ae.arenaTable = :arenaTable
ORDER BY ae.status, ae.arenaTable LIMIT 1000
""")
List<ArenaEvent> findByStatusAndArenaTable(ArenaEventStatus status, String arenaTable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import no.nav.tag.tiltaksgjennomforing.arena.models.event.ArenaEvent;
import no.nav.tag.tiltaksgjennomforing.arena.models.event.ArenaEventStatus;
import no.nav.tag.tiltaksgjennomforing.arena.repository.ArenaEventRepository;
import org.springframework.data.domain.Limit;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -54,14 +53,14 @@ public void process(List<ArenaEvent> arenaEvents) {
}

private List<ArenaEvent> findEventsForProcessing() {
List<ArenaEvent> events = arenaEventRepository.findByStatus(ArenaEventStatus.CREATED, Limit.of(1000));
List<ArenaEvent> events = arenaEventRepository.findByStatus(ArenaEventStatus.CREATED);

if (events.isEmpty() || events.size() <= 100) {
events.addAll(arenaEventRepository.findByStatusAndArenaTable(ArenaEventStatus.RETRY, ArenaTable.TILTAKGJENNOMFORING.getTable(), Limit.of(1000)));
events.addAll(arenaEventRepository.findByStatusAndArenaTable(ArenaEventStatus.RETRY, ArenaTable.TILTAKGJENNOMFORING.getTable()));
}

if (events.isEmpty() || events.size() <= 100) {
events.addAll(arenaEventRepository.findByStatusAndArenaTable(ArenaEventStatus.RETRY, ArenaTable.TILTAKDELTAKER.getTable(), Limit.of(1000)));
events.addAll(arenaEventRepository.findByStatusAndArenaTable(ArenaEventStatus.RETRY, ArenaTable.TILTAKDELTAKER.getTable()));
}

return events;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DROP INDEX IF EXISTS arena_events_arena_op_time_idx;
DROP INDEX IF EXISTS arena_events_arena_retry_count_idx;

CREATE INDEX IF NOT EXISTS arena_event_status_idx ON arena_event(status);
CREATE INDEX IF NOT EXISTS arena_event_status_arena_table_idx ON arena_event(status, arena_table);

0 comments on commit 26e18af

Please sign in to comment.