Skip to content

Commit db28264

Browse files
committed
Add lock file to prevent redundant update checks
Add a lock file based on the current date to the temporary directory to prevent redundant update checks for the Gradle IntelliJ Plugin. The lock file ensures that the checks only happen once per day, reducing unnecessary API calls and improving performance.
1 parent ecead83 commit db28264

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## [next]
44

5+
### Added
6+
- Create a date-based lock file to limit daily update checks for the Gradle IntelliJ Plugin.
7+
58
### Fixed
69
- Handle the `Could not HEAD 'https://www.jetbrains.com/updates/updates.xml'` gracefully when running `downloadIdeaProductReleasesXml` with no Internet connection
710
- Improved checking if `Provider` holds non-empty value

src/main/kotlin/org/jetbrains/intellij/IntelliJPlugin.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
117117
import java.io.File
118118
import java.net.URL
119119
import java.nio.file.Path
120+
import java.time.LocalDate
120121
import java.time.LocalDateTime
121122
import java.time.format.DateTimeFormatter
122123
import java.util.*
@@ -1530,6 +1531,13 @@ abstract class IntelliJPlugin : Plugin<Project> {
15301531
selfUpdateCheck.convention(project.provider {
15311532
project.isBuildFeatureEnabled(SELF_UPDATE_CHECK)
15321533
})
1534+
lockFile.convention(project.provider{
1535+
temporaryDir.resolve(LocalDate.now().toString())
1536+
})
1537+
1538+
onlyIf {
1539+
!lockFile.get().exists()
1540+
}
15331541
}
15341542
}
15351543

src/main/kotlin/org/jetbrains/intellij/tasks/InitializeIntelliJPluginTask.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.jetbrains.intellij.IntelliJPluginConstants.PLUGIN_GROUP_NAME
1313
import org.jetbrains.intellij.IntelliJPluginConstants.PLUGIN_ID
1414
import org.jetbrains.intellij.IntelliJPluginConstants.PLUGIN_NAME
1515
import org.jetbrains.intellij.utils.LatestVersionResolver
16+
import java.io.File
1617

1718
/**
1819
* Initializes the Gradle IntelliJ Plugin and performs various checks, like if the plugin is up to date.
@@ -26,6 +27,9 @@ abstract class InitializeIntelliJPluginTask : DefaultTask() {
2627
@get:Internal
2728
abstract val selfUpdateCheck: Property<Boolean>
2829

30+
@get:Internal
31+
abstract val lockFile: Property<File>
32+
2933
init {
3034
group = PLUGIN_GROUP_NAME
3135
description = "Initializes the Gradle IntelliJ Plugin"
@@ -54,6 +58,8 @@ abstract class InitializeIntelliJPluginTask : DefaultTask() {
5458
if (version < Version.parse(latestVersion)) {
5559
warn(context, "$PLUGIN_NAME is outdated: $version. Update `$PLUGIN_ID` to: $latestVersion")
5660
}
61+
62+
lockFile.get().createNewFile()
5763
} catch (e: Exception) {
5864
error(context, e.message.orEmpty(), e)
5965
}

0 commit comments

Comments
 (0)