Skip to content

Commit

Permalink
Merge pull request #501 from handymenny/fix-reparse
Browse files Browse the repository at this point in the history
reparse: patch index instead of rebuilding it
  • Loading branch information
handymenny authored Oct 5, 2024
2 parents ed2bcca + 8528599 commit e711bfb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
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

0 comments on commit e711bfb

Please sign in to comment.