From edec7a715885fceb269a74990af16652fd986830 Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Tue, 17 Sep 2024 17:23:08 +0300 Subject: [PATCH 1/2] fix find by name --- .../di/factory/SignalDatabaseFactory.kt | 2 ++ .../db/signal/table/SignalNameAliasTable.kt | 12 +++++++++ .../backend/db/signal/table/SignalTable.kt | 1 - .../parser/presentation/FillerController.kt | 26 ++++++++++++++++--- .../presentation/SignalRouteRegistry.kt | 11 ++++---- 5 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/table/SignalNameAliasTable.kt diff --git a/modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/di/factory/SignalDatabaseFactory.kt b/modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/di/factory/SignalDatabaseFactory.kt index 102a381..1483596 100644 --- a/modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/di/factory/SignalDatabaseFactory.kt +++ b/modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/di/factory/SignalDatabaseFactory.kt @@ -7,6 +7,7 @@ import com.flipperdevices.ifrmvp.backend.db.signal.table.CategoryTable import com.flipperdevices.ifrmvp.backend.db.signal.table.InfraredFileTable import com.flipperdevices.ifrmvp.backend.db.signal.table.InfraredFileToSignalTable import com.flipperdevices.ifrmvp.backend.db.signal.table.SignalKeyTable +import com.flipperdevices.ifrmvp.backend.db.signal.table.SignalNameAliasTable import com.flipperdevices.ifrmvp.backend.db.signal.table.SignalTable import com.flipperdevices.ifrmvp.backend.db.signal.table.UiPresetTable import com.flipperdevices.ifrmvp.backend.envkonfig.model.DBConnection @@ -32,6 +33,7 @@ internal class SignalDatabaseFactory( CategoryTable, InfraredFileTable, InfraredFileToSignalTable, + SignalNameAliasTable, SignalTable, SignalKeyTable, UiPresetTable, diff --git a/modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/table/SignalNameAliasTable.kt b/modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/table/SignalNameAliasTable.kt new file mode 100644 index 0000000..d4ddafe --- /dev/null +++ b/modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/table/SignalNameAliasTable.kt @@ -0,0 +1,12 @@ +package com.flipperdevices.ifrmvp.backend.db.signal.table + +import org.jetbrains.exposed.dao.id.LongIdTable + +object SignalNameAliasTable : LongIdTable("SIGNAL_NAME_ALIAS") { + val signalId = reference("signal_id", SignalTable) + val signalName = text("signal_name") + + init { + uniqueIndex(signalId, signalName) + } +} diff --git a/modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/table/SignalTable.kt b/modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/table/SignalTable.kt index f4f97df..51b121d 100644 --- a/modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/table/SignalTable.kt +++ b/modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/table/SignalTable.kt @@ -12,7 +12,6 @@ import org.jetbrains.exposed.dao.id.LongIdTable object SignalTable : LongIdTable("SIGNAL_TABLE") { val brandId = reference("brand_id", BrandTable) - val name = text("name") val type = text("type") val protocol = text("protocol").nullable() val address = text("address").nullable() diff --git a/modules/kenerator/sql/src/main/kotlin/com/flipperdevices/ifrmvp/parser/presentation/FillerController.kt b/modules/kenerator/sql/src/main/kotlin/com/flipperdevices/ifrmvp/parser/presentation/FillerController.kt index 5e367b2..8c63100 100644 --- a/modules/kenerator/sql/src/main/kotlin/com/flipperdevices/ifrmvp/parser/presentation/FillerController.kt +++ b/modules/kenerator/sql/src/main/kotlin/com/flipperdevices/ifrmvp/parser/presentation/FillerController.kt @@ -8,6 +8,7 @@ import com.flipperdevices.ifrmvp.backend.db.signal.table.CategoryTable import com.flipperdevices.ifrmvp.backend.db.signal.table.InfraredFileTable import com.flipperdevices.ifrmvp.backend.db.signal.table.InfraredFileToSignalTable import com.flipperdevices.ifrmvp.backend.db.signal.table.SignalKeyTable +import com.flipperdevices.ifrmvp.backend.db.signal.table.SignalNameAliasTable import com.flipperdevices.ifrmvp.backend.db.signal.table.SignalTable import com.flipperdevices.ifrmvp.backend.db.signal.table.UiPresetTable import com.flipperdevices.ifrmvp.model.IfrKeyIdentifier @@ -17,7 +18,10 @@ import com.flipperdevices.infrared.editor.model.InfraredRemote import com.flipperdevices.infrared.editor.util.InfraredMapper import com.flipperdevices.infrared.editor.viewmodel.InfraredKeyParser import java.io.File +import kotlin.math.sign +import kotlin.time.measureTime import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.async import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.JoinType import org.jetbrains.exposed.sql.andWhere @@ -103,7 +107,6 @@ internal class FillerController(private val database: Database) : CoroutineScope val parsedRemote = remote as? InfraredRemote.Parsed val rawRemote = remote as? InfraredRemote.Raw this[SignalTable.brandId] = brandId - this[SignalTable.name] = remote.name this[SignalTable.type] = remote.type this[SignalTable.protocol] = parsedRemote?.protocol this[SignalTable.address] = parsedRemote?.address @@ -143,6 +146,12 @@ internal class FillerController(private val database: Database) : CoroutineScope """.trimIndent() ) } + + SignalNameAliasTable.batchInsert(signalIds.zip(signals), ignore = true) { + this[SignalNameAliasTable.signalName] = it.second.name + this[SignalNameAliasTable.signalId] = it.first.value + } + InfraredFileToSignalTable.batchInsert(signalIds) { this[InfraredFileToSignalTable.infraredFileId] = irFileId this[InfraredFileToSignalTable.signalId] = it @@ -164,7 +173,10 @@ internal class FillerController(private val database: Database) : CoroutineScope this[SignalKeyTable.type] = IfrKeyIdentifier.Empty.TYPE } - is IfrKeyIdentifier.Name -> error("Identifying by name is not possible!") + is IfrKeyIdentifier.Name -> { + this[SignalKeyTable.remoteKeyName] = keyIdentifier.name + this[SignalKeyTable.type] = IfrKeyIdentifier.Sha256.TYPE + } is IfrKeyIdentifier.Sha256 -> { this[SignalKeyTable.remoteKeyName] = keyIdentifier.name @@ -180,6 +192,12 @@ internal class FillerController(private val database: Database) : CoroutineScope onColumn = SignalTable.id, otherColumn = InfraredFileToSignalTable.signalId ) + .join( + otherTable = SignalNameAliasTable, + joinType = JoinType.LEFT, + onColumn = SignalTable.id, + otherColumn = SignalNameAliasTable.signalId + ) .select(SignalTable.id) .where { SignalTable.brandId eq brandId } .andWhere { InfraredFileToSignalTable.infraredFileId eq irFileId } @@ -191,7 +209,9 @@ internal class FillerController(private val database: Database) : CoroutineScope andWhere { SignalTable.hash eq keyIdentifier.hash } } - is IfrKeyIdentifier.Name -> error("Identifying by name is not possible!") + is IfrKeyIdentifier.Name -> { + andWhere { SignalNameAliasTable.signalName eq keyIdentifier.name } + } } } .map { it[SignalTable.id] } diff --git a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/signal/presentation/SignalRouteRegistry.kt b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/signal/presentation/SignalRouteRegistry.kt index 8aed98b..fc4bef9 100644 --- a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/signal/presentation/SignalRouteRegistry.kt +++ b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/signal/presentation/SignalRouteRegistry.kt @@ -6,6 +6,7 @@ import com.flipperdevices.ifrmvp.backend.db.signal.exception.TableDaoException import com.flipperdevices.ifrmvp.backend.db.signal.table.InfraredFileTable import com.flipperdevices.ifrmvp.backend.db.signal.table.InfraredFileToSignalTable import com.flipperdevices.ifrmvp.backend.db.signal.table.SignalKeyTable +import com.flipperdevices.ifrmvp.backend.db.signal.table.SignalNameAliasTable import com.flipperdevices.ifrmvp.backend.db.signal.table.SignalTable import com.flipperdevices.ifrmvp.backend.model.BrandModel import com.flipperdevices.ifrmvp.backend.model.CategoryConfiguration @@ -196,7 +197,7 @@ internal class SignalRouteRegistry( SignalModel( id = it[SignalTable.id].value, remote = SignalModel.FlipperRemote( - name = it[SignalTable.name], + name = "empty", type = it[SignalTable.type], protocol = it[SignalTable.protocol], address = it[SignalTable.address], @@ -238,13 +239,13 @@ internal class SignalRouteRegistry( } val skippedKeys = transaction(database) { - SignalTable + SignalNameAliasTable .selectAll() - .where { SignalTable.id inList signalRequestModel.skippedResults.map(SignalRequestModel.SignalResultData::signalId) } + .where { SignalNameAliasTable.id inList signalRequestModel.skippedResults.map(SignalRequestModel.SignalResultData::signalId) } .mapNotNull { - val keyName = it[SignalTable.name] + val keyName = it[SignalNameAliasTable.signalName] AnyDeviceKeyNamesProvider.getKey(keyName) - } + }.distinct() } val signalModel = getSignalModel( From 41ac9c6a04ce8651a29d098ce439ddc4ee35db73 Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Tue, 17 Sep 2024 17:25:11 +0300 Subject: [PATCH 2/2] up version 0.7.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 4e86d4c..14aaccf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.parallel=true makeevrserg.project.name=IRDBBackend makeevrserg.project.url=https://github.com/flipperdevices/IRDB-Backend makeevrserg.project.group=com.flipperdevices.ifrmvp.backend -makeevrserg.project.version.string=0.6.0 +makeevrserg.project.version.string=0.7.0 makeevrserg.project.description=Api for IfrSample makeevrserg.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com # Java