mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-09 16:45:46 -07:00
Parallel fetch
This commit is contained in:
parent
3fae644550
commit
07e5fb08b3
2 changed files with 49 additions and 13 deletions
|
|
@ -8,6 +8,7 @@ import java.io.BufferedReader
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
import java.util.concurrent.*
|
||||||
import javax.swing.SwingUtilities
|
import javax.swing.SwingUtilities
|
||||||
|
|
||||||
object GitLabPluginFetcher {
|
object GitLabPluginFetcher {
|
||||||
|
|
@ -16,6 +17,9 @@ object GitLabPluginFetcher {
|
||||||
private const val CHROME_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
private const val CHROME_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
||||||
private const val DEBUG = true // Set to false to disable debug logging
|
private const val DEBUG = true // Set to false to disable debug logging
|
||||||
|
|
||||||
|
// Thread pool for concurrent plugin property fetching
|
||||||
|
private val executorService = Executors.newFixedThreadPool(5)
|
||||||
|
|
||||||
// Debug logging function
|
// Debug logging function
|
||||||
private fun debugLog(message: String) {
|
private fun debugLog(message: String) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
|
|
@ -55,25 +59,41 @@ object GitLabPluginFetcher {
|
||||||
debugLog("Parsed ${treeItems.size} items from JSON")
|
debugLog("Parsed ${treeItems.size} items from JSON")
|
||||||
|
|
||||||
// Filter for directories (trees) with mode "040000"
|
// Filter for directories (trees) with mode "040000"
|
||||||
var directoryCount = 0
|
val pluginDirectories = mutableListOf<Pair<String, String>>()
|
||||||
for (jsonObject in treeItems) {
|
for (jsonObject in treeItems) {
|
||||||
if (jsonObject["type"].asString == "tree" && jsonObject["mode"].asString == "040000") {
|
if (jsonObject["type"].asString == "tree" && jsonObject["mode"].asString == "040000") {
|
||||||
directoryCount++
|
|
||||||
val folderId = jsonObject["id"].asString
|
val folderId = jsonObject["id"].asString
|
||||||
val folderPath = jsonObject["path"].asString
|
val folderPath = jsonObject["path"].asString
|
||||||
debugLog("Processing directory: $folderPath (ID: $folderId)")
|
pluginDirectories.add(folderId to folderPath)
|
||||||
|
debugLog("Found directory: $folderPath (ID: $folderId)")
|
||||||
try {
|
}
|
||||||
val pluginProperties = fetchPluginProperties(folderPath)
|
}
|
||||||
plugins.add(GitLabPlugin(folderId, folderPath, pluginProperties, null))
|
debugLog("Found ${pluginDirectories.size} plugin directories")
|
||||||
debugLog("Successfully fetched properties for: $folderPath")
|
|
||||||
} catch (e: Exception) {
|
// Fetch plugin properties in parallel
|
||||||
debugLog("Error fetching plugin.properties for $folderPath: ${e.message}")
|
val pluginFutures = mutableListOf<Future<GitLabPlugin>>()
|
||||||
plugins.add(GitLabPlugin(folderId, folderPath, null, "Error fetching plugin.properties"))
|
for ((folderId, folderPath) in pluginDirectories) {
|
||||||
}
|
val future = executorService.submit(Callable<GitLabPlugin> {
|
||||||
|
try {
|
||||||
|
val pluginProperties = fetchPluginProperties(folderPath)
|
||||||
|
debugLog("Successfully fetched properties for: $folderPath")
|
||||||
|
GitLabPlugin(folderId, folderPath, pluginProperties, null)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
debugLog("Error fetching plugin.properties for $folderPath: ${e.message}")
|
||||||
|
GitLabPlugin(folderId, folderPath, null, "Error fetching plugin.properties")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
pluginFutures.add(future)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect results
|
||||||
|
for (future in pluginFutures) {
|
||||||
|
try {
|
||||||
|
plugins.add(future.get())
|
||||||
|
} catch (e: Exception) {
|
||||||
|
debugLog("Error getting plugin result: ${e.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debugLog("Found $directoryCount directories (trees)")
|
|
||||||
} else {
|
} else {
|
||||||
debugLog("HTTP error: $responseCode")
|
debugLog("HTTP error: $responseCode")
|
||||||
val errorReader = BufferedReader(InputStreamReader(connection.errorStream))
|
val errorReader = BufferedReader(InputStreamReader(connection.errorStream))
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package KondoKit.components.ReflectiveEditorComponents
|
package KondoKit.components.ReflectiveEditorComponents
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple test to verify GitLabPluginFetcher debug logging works
|
* Simple test to verify GitLabPluginFetcher debug logging works
|
||||||
*/
|
*/
|
||||||
|
|
@ -11,6 +14,19 @@ fun main() {
|
||||||
plugins.forEach { plugin ->
|
plugins.forEach { plugin ->
|
||||||
println("- ${plugin.path}: ${plugin.pluginProperties?.description ?: plugin.pluginError}")
|
println("- ${plugin.path}: ${plugin.pluginProperties?.description ?: plugin.pluginError}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shutdown the executor service
|
||||||
|
try {
|
||||||
|
val field = GitLabPluginFetcher::class.java.getDeclaredField("executorService")
|
||||||
|
field.isAccessible = true
|
||||||
|
val executorService = field.get(GitLabPluginFetcher) as ExecutorService
|
||||||
|
executorService.shutdown()
|
||||||
|
if (!executorService.awaitTermination(5, TimeUnit.SECONDS)) {
|
||||||
|
executorService.shutdownNow()
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give the async fetch some time to complete
|
// Give the async fetch some time to complete
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue