Skip to content

Commit

Permalink
Only update mappings if they have not already been updated
Browse files Browse the repository at this point in the history
Signed-off-by: Chase Engelbrecht <[email protected]>
  • Loading branch information
engechas committed Feb 13, 2024
1 parent b0c8afc commit 9ea9daa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class AlertIndices(
dataSources.alertsHistoryIndex
)
} else {
// TODO - why do we need explicit mappings?
updateIndexMapping(
dataSources.alertsHistoryIndex ?: ALERT_HISTORY_WRITE_INDEX,
alertMapping(),
Expand Down Expand Up @@ -380,7 +381,7 @@ class AlertIndices(
}

// TODO call getMapping and compare actual mappings here instead of this
if (targetIndex == IndexUtils.lastUpdatedAlertHistoryIndex || targetIndex == IndexUtils.lastUpdatedFindingHistoryIndex) {
if (IndexUtils.initializedIndices.contains(targetIndex)) {
return
}

Expand All @@ -396,6 +397,7 @@ class AlertIndices(
}

private fun setIndexUpdateFlag(index: String, targetIndex: String) {
IndexUtils.initializedIndices.add(targetIndex)
when (index) {
ALERT_INDEX -> IndexUtils.alertIndexUpdated()
ALERT_HISTORY_WRITE_INDEX -> IndexUtils.lastUpdatedAlertHistoryIndex = targetIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class IndexUtils {
var lastUpdatedAlertHistoryIndex: String? = null
var lastUpdatedFindingHistoryIndex: String? = null

var initializedIndices: MutableSet<String> = mutableSetOf()

init {
scheduledJobIndexSchemaVersion = getSchemaVersion(ScheduledJobIndices.scheduledJobMappings())
alertIndexSchemaVersion = getSchemaVersion(AlertIndices.alertMapping())
Expand Down

0 comments on commit 9ea9daa

Please sign in to comment.