Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reparse: patch index instead of rebuilding it #501

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ data class LibraryIndex(
}
}

fun replaceLine(line: IndexLine): Boolean {
synchronized(lock) {
items.removeIf { it.id == line.id }
items.add(line)
outputCache.remove(line.id)
}
return true
}

fun addMultiLine(line: MultiIndexLine): Boolean {
synchronized(lock) {
return multiItems.add(line)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ class JavalinApp {
if (reparseStrategy != "off") {
CoroutineScope(Dispatchers.IO).launch {
reparseLibrary(reparseStrategy, store, index, compression)
// Rebuild index
index = LibraryIndex.buildIndex(store, maxOutputCache)
}
}
}
Expand Down Expand Up @@ -123,12 +121,17 @@ class JavalinApp {
index
.getAll()
.filterNot { auto && it.parserVersion == parserVersion }
.map { async { reparseItem(it, store, compression) } }
.map { async { reparseItem(it, index, store, compression) } }
.awaitAll()
}
}

private fun reparseItem(indexLine: IndexLine, store: String, compression: Boolean) {
private fun reparseItem(
indexLine: IndexLine,
index: LibraryIndex,
store: String,
compression: Boolean,
) {
val compressed = indexLine.compressed
val capPath = "/output/${indexLine.id}.json"
try {
Expand Down Expand Up @@ -160,6 +163,9 @@ class JavalinApp {
it.capabilities.timestamp = capabilities.timestamp
it.store(null, store, compression)
} ?: throw NullPointerException("Reparsed Capabilities is null")

val newLine = indexLine.copy(compressed = compression)
index.replaceLine(newLine)
} catch (ex: Exception) {
echoSafe("Error re-parsing ${indexLine.id}:\t${ex.message}", true)
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class LruCache<K, V>(private val maxCapacity: Int? = null) {

operator fun set(key: K, value: V) = put(key, value)

fun remove(key: K): V? {
synchronized(lock) {
return internalMap.remove(key)
}
}

fun put(key: K, value: V, skipIfFull: Boolean = false): Boolean {
if (maxCapacity == 0 || skipIfFull && full()) return false
synchronized(lock) { internalMap[key] = value }
Expand Down