Avoid recalculating the same replay similarity if the replay set hasn't changed

This commit is contained in:
nise.moe 2024-02-22 20:48:19 +01:00
parent 60e6f05fdf
commit fd6d23327c
4 changed files with 48 additions and 14 deletions

View File

@ -16,7 +16,7 @@ import org.jooq.ForeignKey
import org.jooq.Name
import org.jooq.Record
import org.jooq.Records
import org.jooq.Row9
import org.jooq.Row10
import org.jooq.Schema
import org.jooq.SelectField
import org.jooq.Table
@ -107,6 +107,11 @@ open class Beatmaps(
*/
val SYS_LAST_UPDATE: TableField<BeatmapsRecord, OffsetDateTime?> = createField(DSL.name("sys_last_update"), SQLDataType.TIMESTAMPWITHTIMEZONE(6).defaultValue(DSL.field(DSL.raw("CURRENT_TIMESTAMP"), SQLDataType.TIMESTAMPWITHTIMEZONE)), this, "")
/**
* The column <code>public.beatmaps.last_replay_check</code>.
*/
val LAST_REPLAY_CHECK: TableField<BeatmapsRecord, String?> = createField(DSL.name("last_replay_check"), SQLDataType.CLOB, this, "")
private constructor(alias: Name, aliased: Table<BeatmapsRecord>?): this(alias, null, null, aliased, null)
private constructor(alias: Name, aliased: Table<BeatmapsRecord>?, parameters: Array<Field<*>?>?): this(alias, null, null, aliased, parameters)
@ -148,18 +153,18 @@ open class Beatmaps(
override fun rename(name: Table<*>): Beatmaps = Beatmaps(name.getQualifiedName(), null)
// -------------------------------------------------------------------------
// Row9 type methods
// Row10 type methods
// -------------------------------------------------------------------------
override fun fieldsRow(): Row9<Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?> = super.fieldsRow() as Row9<Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?>
override fun fieldsRow(): Row10<Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?, String?> = super.fieldsRow() as Row10<Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?, String?>
/**
* Convenience mapping calling {@link SelectField#convertFrom(Function)}.
*/
fun <U> mapping(from: (Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?) -> U): SelectField<U> = convertFrom(Records.mapping(from))
fun <U> mapping(from: (Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?, String?) -> U): SelectField<U> = convertFrom(Records.mapping(from))
/**
* Convenience mapping calling {@link SelectField#convertFrom(Class,
* Function)}.
*/
fun <U> mapping(toType: Class<U>, from: (Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?) -> U): SelectField<U> = convertFrom(toType, Records.mapping(from))
fun <U> mapping(toType: Class<U>, from: (Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?, String?) -> U): SelectField<U> = convertFrom(toType, Records.mapping(from))
}

View File

@ -10,8 +10,8 @@ import java.time.OffsetDateTime
import org.jooq.Field
import org.jooq.Record1
import org.jooq.Record9
import org.jooq.Row9
import org.jooq.Record10
import org.jooq.Row10
import org.jooq.impl.UpdatableRecordImpl
@ -19,7 +19,7 @@ import org.jooq.impl.UpdatableRecordImpl
* This class is generated by jOOQ.
*/
@Suppress("UNCHECKED_CAST")
open class BeatmapsRecord private constructor() : UpdatableRecordImpl<BeatmapsRecord>(Beatmaps.BEATMAPS), Record9<Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?> {
open class BeatmapsRecord private constructor() : UpdatableRecordImpl<BeatmapsRecord>(Beatmaps.BEATMAPS), Record10<Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?, String?> {
open var beatmapId: Int?
set(value): Unit = set(0, value)
@ -57,6 +57,10 @@ open class BeatmapsRecord private constructor() : UpdatableRecordImpl<BeatmapsRe
set(value): Unit = set(8, value)
get(): OffsetDateTime? = get(8) as OffsetDateTime?
open var lastReplayCheck: String?
set(value): Unit = set(9, value)
get(): String? = get(9) as String?
// -------------------------------------------------------------------------
// Primary key information
// -------------------------------------------------------------------------
@ -64,11 +68,11 @@ open class BeatmapsRecord private constructor() : UpdatableRecordImpl<BeatmapsRe
override fun key(): Record1<Int?> = super.key() as Record1<Int?>
// -------------------------------------------------------------------------
// Record9 type implementation
// Record10 type implementation
// -------------------------------------------------------------------------
override fun fieldsRow(): Row9<Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?> = super.fieldsRow() as Row9<Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?>
override fun valuesRow(): Row9<Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?> = super.valuesRow() as Row9<Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?>
override fun fieldsRow(): Row10<Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?, String?> = super.fieldsRow() as Row10<Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?, String?>
override fun valuesRow(): Row10<Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?, String?> = super.valuesRow() as Row10<Int?, String?, Int?, String?, String?, Double?, String?, String?, OffsetDateTime?, String?>
override fun field1(): Field<Int?> = Beatmaps.BEATMAPS.BEATMAP_ID
override fun field2(): Field<String?> = Beatmaps.BEATMAPS.ARTIST
override fun field3(): Field<Int?> = Beatmaps.BEATMAPS.BEATMAPSET_ID
@ -78,6 +82,7 @@ open class BeatmapsRecord private constructor() : UpdatableRecordImpl<BeatmapsRe
override fun field7(): Field<String?> = Beatmaps.BEATMAPS.TITLE
override fun field8(): Field<String?> = Beatmaps.BEATMAPS.VERSION
override fun field9(): Field<OffsetDateTime?> = Beatmaps.BEATMAPS.SYS_LAST_UPDATE
override fun field10(): Field<String?> = Beatmaps.BEATMAPS.LAST_REPLAY_CHECK
override fun component1(): Int? = beatmapId
override fun component2(): String? = artist
override fun component3(): Int? = beatmapsetId
@ -87,6 +92,7 @@ open class BeatmapsRecord private constructor() : UpdatableRecordImpl<BeatmapsRe
override fun component7(): String? = title
override fun component8(): String? = version
override fun component9(): OffsetDateTime? = sysLastUpdate
override fun component10(): String? = lastReplayCheck
override fun value1(): Int? = beatmapId
override fun value2(): String? = artist
override fun value3(): Int? = beatmapsetId
@ -96,6 +102,7 @@ open class BeatmapsRecord private constructor() : UpdatableRecordImpl<BeatmapsRe
override fun value7(): String? = title
override fun value8(): String? = version
override fun value9(): OffsetDateTime? = sysLastUpdate
override fun value10(): String? = lastReplayCheck
override fun value1(value: Int?): BeatmapsRecord {
set(0, value)
@ -142,7 +149,12 @@ open class BeatmapsRecord private constructor() : UpdatableRecordImpl<BeatmapsRe
return this
}
override fun values(value1: Int?, value2: String?, value3: Int?, value4: String?, value5: String?, value6: Double?, value7: String?, value8: String?, value9: OffsetDateTime?): BeatmapsRecord {
override fun value10(value: String?): BeatmapsRecord {
set(9, value)
return this
}
override fun values(value1: Int?, value2: String?, value3: Int?, value4: String?, value5: String?, value6: Double?, value7: String?, value8: String?, value9: OffsetDateTime?, value10: String?): BeatmapsRecord {
this.value1(value1)
this.value2(value2)
this.value3(value3)
@ -152,13 +164,14 @@ open class BeatmapsRecord private constructor() : UpdatableRecordImpl<BeatmapsRe
this.value7(value7)
this.value8(value8)
this.value9(value9)
this.value10(value10)
return this
}
/**
* Create a detached, initialised BeatmapsRecord
*/
constructor(beatmapId: Int? = null, artist: String? = null, beatmapsetId: Int? = null, creator: String? = null, source: String? = null, starRating: Double? = null, title: String? = null, version: String? = null, sysLastUpdate: OffsetDateTime? = null): this() {
constructor(beatmapId: Int? = null, artist: String? = null, beatmapsetId: Int? = null, creator: String? = null, source: String? = null, starRating: Double? = null, title: String? = null, version: String? = null, sysLastUpdate: OffsetDateTime? = null, lastReplayCheck: String? = null): this() {
this.beatmapId = beatmapId
this.artist = artist
this.beatmapsetId = beatmapsetId
@ -168,6 +181,7 @@ open class BeatmapsRecord private constructor() : UpdatableRecordImpl<BeatmapsRe
this.title = title
this.version = version
this.sysLastUpdate = sysLastUpdate
this.lastReplayCheck = lastReplayCheck
resetChangedOnNotNull()
}
}

View File

@ -444,7 +444,7 @@ class ImportScores(
val sw = StopWatch()
private fun checkReplaySimilarity(beatmapId: Int) {
fun checkReplaySimilarity(beatmapId: Int) {
val allReplays = dslContext.select(
SCORES.REPLAY_ID.`as`("replayId"),
SCORES.MODS.`as`("replayMods"),
@ -461,6 +461,13 @@ class ImportScores(
return
}
val replaySetId = allReplays.map { it.replayId }.sortedDescending().joinToString("/")
if(dslContext.fetchExists(BEATMAPS, BEATMAPS.BEATMAP_ID.eq(beatmapId).and(BEATMAPS.LAST_REPLAY_CHECK.eq(replaySetId)))) {
this.logger.debug("Replay set already processed for beatmapId = $beatmapId.")
return
}
sw.start("konata")
val konataResults: List<ReplaySetComparison> = try {
@ -548,6 +555,12 @@ class ImportScores(
}
dslContext.batch(queries).execute()
// Save the replay set so that it doesnt' get calculated again
dslContext.update(BEATMAPS)
.set(BEATMAPS.LAST_REPLAY_CHECK, replaySetId)
.where(BEATMAPS.BEATMAP_ID.eq(beatmapId))
.execute()
}
private fun insertAndProcessNewScore(beatmapId: Int, score: OsuApiModels.Score, isUserQueue: Boolean = false) {

View File

@ -0,0 +1,2 @@
ALTER TABLE public.beatmaps
ADD COLUMN last_replay_check text;