forked from SteamWar/SteamWar
Sort fights by start time in descending order and refactor saveFromStream method to use useDb block.
Signed-off-by: Chaoscaot <max@maxsp.de>
This commit is contained in:
@@ -25,6 +25,7 @@ import org.jetbrains.exposed.v1.core.dao.id.IdTable
|
|||||||
import org.jetbrains.exposed.v1.core.eq
|
import org.jetbrains.exposed.v1.core.eq
|
||||||
import org.jetbrains.exposed.v1.dao.IntEntity
|
import org.jetbrains.exposed.v1.dao.IntEntity
|
||||||
import org.jetbrains.exposed.v1.dao.IntEntityClass
|
import org.jetbrains.exposed.v1.dao.IntEntityClass
|
||||||
|
import org.jetbrains.exposed.v1.javatime.CurrentTimestamp
|
||||||
import org.jetbrains.exposed.v1.javatime.timestamp
|
import org.jetbrains.exposed.v1.javatime.timestamp
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import java.sql.Timestamp
|
import java.sql.Timestamp
|
||||||
@@ -33,7 +34,7 @@ import java.time.Instant
|
|||||||
object NodeDownloadTable: IdTable<Int>("NodeDownload") {
|
object NodeDownloadTable: IdTable<Int>("NodeDownload") {
|
||||||
override val id = reference("NodeId", SchematicNodeTable).uniqueIndex()
|
override val id = reference("NodeId", SchematicNodeTable).uniqueIndex()
|
||||||
val link = varchar("Link", 255)
|
val link = varchar("Link", 255)
|
||||||
val timestamp = timestamp("Timestamp").default(Instant.now())
|
val timestamp = timestamp("Timestamp").defaultExpression(CurrentTimestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
class NodeDownload(id: EntityID<Int>) : IntEntity(id) {
|
class NodeDownload(id: EntityID<Int>) : IntEntity(id) {
|
||||||
@@ -49,7 +50,9 @@ class NodeDownload(id: EntityID<Int>) : IntEntity(id) {
|
|||||||
digest.update("${Instant.now()}${schem.owner}${schem.nodeId}".toByteArray())
|
digest.update("${Instant.now()}${schem.owner}${schem.nodeId}".toByteArray())
|
||||||
val hash = digest.digest().joinToString("") { "%02x".format(it) }
|
val hash = digest.digest().joinToString("") { "%02x".format(it) }
|
||||||
useDb {
|
useDb {
|
||||||
new {
|
findByIdAndUpdate(schem.id.value) {
|
||||||
|
it.link = hash
|
||||||
|
} ?: new {
|
||||||
nodeId = schem.id.value
|
nodeId = schem.id.value
|
||||||
link = hash
|
link = hash
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user