Skip to content

Commit

Permalink
Attempt to optimize query
Browse files Browse the repository at this point in the history
  • Loading branch information
mbryzek committed Jun 7, 2024
1 parent 506d47d commit 7cfe5c8
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions api/app/processor/ScheduleMigrateVersionsProcessor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,19 @@ class ScheduleMigrateVersionsProcessor @Inject()(
}


private[this] val Limit = 1000
private[this] val VersionsNeedingUpgrade = Query(
"""
s"""
|select v.guid
| from versions v
| join applications apps on apps.guid = v.application_guid and apps.deleted_at is null
| left join tasks t on t.type = {task_type} and t.type_id::uuid = v.guid
| left join cache.services on services.deleted_at is null
| and services.version_guid = v.guid
| and services.version = {service_version}
| where v.deleted_at is null
| and t.id is null
| and not exists (
| select 1
| from cache.services
| where services.deleted_at is null
| and services.version_guid = v.guid
| and services.version = {service_version}
| )
|limit 250
| and services.guid is null
| and v.guid not in (select type_id::uuid from tasks where type = {task_type})
|limit $Limit
|""".stripMargin
).bind("service_version", MigrateVersion.ServiceVersionNumber)
.bind("task_type", TaskType.MigrateVersion.toString)
Expand All @@ -51,7 +48,9 @@ class ScheduleMigrateVersionsProcessor @Inject()(
}
if (versionGuids.nonEmpty) {
internalTasksDao.queueBatch(TaskType.MigrateVersion, versionGuids.map(_.toString))
scheduleMigrationTasks()
if (versionGuids.length >= Limit) {
scheduleMigrationTasks()
}
}
}
}

0 comments on commit 7cfe5c8

Please sign in to comment.