Skip to content

Commit 704bbe2

Browse files
committed
feat: batch submit event log
1 parent f33dae6 commit 704bbe2

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,8 @@
44

55
## [Unreleased]
66
### Added
7+
- batch submit event log
78

8-
### Changed
9-
10-
### Deprecated
11-
12-
### Removed
13-
14-
### Fixed
15-
16-
### Security
179
## [0.0.6]
1810
### Added
1911
- add plugin vendor

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
pluginGroup = com.github.si9ma.codetimejetbrains
55
pluginName_ = codetime
6-
pluginVersion = 0.0.6
6+
pluginVersion = 0.0.7
77
pluginSinceBuild = 193
88
pluginUntilBuild = 203.*
99
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl

src/main/kotlin/com/github/si9ma/codetimejetbrains/listeners/CodeTimeProjectManagerListener.kt

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import java.util.UUID
2323
import kotlin.concurrent.timerTask
2424

2525
const val TIMER_DELAY = 100
26-
const val TIMER_PERIOD = 100
26+
const val TIMER_PERIOD = 30 * 1000
27+
const val PLUGIN_NAME = "codetime-jetbrains"
28+
const val PLUGIN_VERSION = "0.0.7"
2729

2830
class CodeTimeProjectManagerListener : ProjectManagerListener {
2931
private val log: Logger = Logger.getInstance("CodeTime")
@@ -43,10 +45,15 @@ class CodeTimeProjectManagerListener : ProjectManagerListener {
4345
Timer().scheduleAtFixedRate(
4446
timerTask {
4547
if (Queue.logQueue.size > 0) {
46-
while (true) {
47-
val event: MutableMap<String, Any> = Queue.logQueue.poll() ?: break
48-
submitEventLog(project, uuid, event)
48+
val events: MutableList<MutableMap<String, Any>> = ArrayList()
49+
val total = Queue.logQueue.size
50+
var idx = 0
51+
while (idx < total) {
52+
val event = Queue.logQueue.poll()
53+
events.add(event)
54+
idx++
4955
}
56+
submitEventLog(project, uuid, events)
5057
}
5158
},
5259
toLong(TIMER_DELAY),
@@ -63,20 +70,24 @@ class CodeTimeProjectManagerListener : ProjectManagerListener {
6370
)
6471
}
6572

66-
private fun submitEventLog(project: Project, uuid: String, event: MutableMap<String, Any>) {
73+
private fun submitEventLog(project: Project, uuid: String, events: MutableList<MutableMap<String, Any>>) {
6774
val projectPath: String? = project.guessProjectDir()?.path
68-
val absoluteFile = event["absoluteFile"]
69-
event["project"] = project.name
70-
event["platform"] = System.getProperty("os.name")
71-
event["platformVersion"] = System.getProperty("os.version")
72-
event["platformArch"] = System.getProperty("os.arch")
73-
event["editor"] = ApplicationNamesInfo.getInstance().fullProductName
74-
event["editorVersion"] = ApplicationInfo.getInstance().fullVersion
75-
event["sessionID"] = uuid
76-
event["relativeFile"] = projectPath?.let { absoluteFile.toString().removePrefix(it) } ?: ""
77-
Fuel.post("https://codetime-api.datreks.com/eventLog")
75+
for (event in events) {
76+
val absoluteFile = event["absoluteFile"]
77+
event["project"] = project.name
78+
event["platform"] = System.getProperty("os.name")
79+
event["platformVersion"] = System.getProperty("os.version")
80+
event["platformArch"] = System.getProperty("os.arch")
81+
event["editor"] = ApplicationNamesInfo.getInstance().fullProductName
82+
event["editorVersion"] = ApplicationInfo.getInstance().fullVersion
83+
event["sessionID"] = uuid
84+
event["plugin"] = PLUGIN_NAME
85+
event["pluginVersion"] = PLUGIN_VERSION
86+
event["relativeFile"] = projectPath?.let { absoluteFile.toString().removePrefix(it) } ?: ""
87+
}
88+
Fuel.post("https://codetime-api.datreks.com/batchEventLog")
7889
.header("token", PluginStateComponent.instance.state.token)
79-
.jsonBody(Klaxon().toJsonString(event)).responseJson() { _, _, result ->
90+
.jsonBody(Klaxon().toJsonString(events)).responseJson() { _, _, result ->
8091
result.fold(
8192
success = {
8293
if (PluginStateComponent.instance.state.debug) {

0 commit comments

Comments
 (0)