diff --git a/src/main/java/it/smartphonecombo/uecapabilityparser/model/index/LibraryIndex.kt b/src/main/java/it/smartphonecombo/uecapabilityparser/model/index/LibraryIndex.kt index a3de9e53..919854f3 100644 --- a/src/main/java/it/smartphonecombo/uecapabilityparser/model/index/LibraryIndex.kt +++ b/src/main/java/it/smartphonecombo/uecapabilityparser/model/index/LibraryIndex.kt @@ -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) diff --git a/src/main/java/it/smartphonecombo/uecapabilityparser/server/JavalinApp.kt b/src/main/java/it/smartphonecombo/uecapabilityparser/server/JavalinApp.kt index b0885526..88900072 100644 --- a/src/main/java/it/smartphonecombo/uecapabilityparser/server/JavalinApp.kt +++ b/src/main/java/it/smartphonecombo/uecapabilityparser/server/JavalinApp.kt @@ -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) } } } @@ -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 { @@ -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 { diff --git a/src/main/java/it/smartphonecombo/uecapabilityparser/util/LruCache.kt b/src/main/java/it/smartphonecombo/uecapabilityparser/util/LruCache.kt index 898f8091..f5208414 100644 --- a/src/main/java/it/smartphonecombo/uecapabilityparser/util/LruCache.kt +++ b/src/main/java/it/smartphonecombo/uecapabilityparser/util/LruCache.kt @@ -21,6 +21,12 @@ class LruCache(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 }