mirror of https://github.com/usbharu/Hideout.git
commit
dd9749a536
|
@ -30,7 +30,8 @@ abstract class AbstractApplicationService<T : Any, R>(
|
|||
val response = transaction.transaction<R> {
|
||||
internalExecute(command, principal)
|
||||
}
|
||||
logger.info("SUCCESS ${command::class.simpleName}")
|
||||
|
||||
logger.info("SUCCESS $command $response")
|
||||
response
|
||||
} catch (e: CancellationException) {
|
||||
logger.debug("Coroutine canceled", e)
|
||||
|
|
|
@ -42,6 +42,16 @@ class UserDetail(
|
|||
}
|
||||
|
||||
override fun hashCode(): Int = id.hashCode()
|
||||
override fun toString(): String {
|
||||
return "UserDetail(" +
|
||||
"id=$id, " +
|
||||
"actorId=$actorId, " +
|
||||
"password=$password, " +
|
||||
"autoAcceptFolloweeFollowRequest=$autoAcceptFolloweeFollowRequest, " +
|
||||
"lastMigration=$lastMigration, " +
|
||||
"homeTimelineId=$homeTimelineId" +
|
||||
")"
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Suppress("LongParameterList")
|
||||
|
|
|
@ -17,4 +17,8 @@
|
|||
package dev.usbharu.hideout.core.domain.model.userdetails
|
||||
|
||||
@JvmInline
|
||||
value class UserDetailHashedPassword(val password: String)
|
||||
value class UserDetailHashedPassword(val password: String) {
|
||||
override fun toString(): String {
|
||||
return "[MASKED]"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,4 +17,8 @@
|
|||
package dev.usbharu.hideout.core.domain.model.userdetails
|
||||
|
||||
@JvmInline
|
||||
value class UserDetailId(val id: Long)
|
||||
value class UserDetailId(val id: Long) {
|
||||
override fun toString(): String {
|
||||
return "UserDetailId(id=$id)"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,9 +24,9 @@ import java.time.Instant
|
|||
|
||||
@Suppress("MagicNumber")
|
||||
open class SnowflakeIdGenerateService(private val baseTime: Long) : IdGenerateService {
|
||||
var lastTimeStamp: Long = -1
|
||||
var sequenceId: Int = 0
|
||||
val mutex = Mutex()
|
||||
private var lastTimeStamp: Long = -1
|
||||
private var sequenceId: Long = 0
|
||||
private val mutex = Mutex()
|
||||
|
||||
@Throws(IllegalStateException::class)
|
||||
override suspend fun generateId(): Long {
|
||||
|
@ -34,7 +34,6 @@ open class SnowflakeIdGenerateService(private val baseTime: Long) : IdGenerateSe
|
|||
var timestamp = getTime()
|
||||
if (timestamp < lastTimeStamp) {
|
||||
timestamp = wait(timestamp)
|
||||
// throw IllegalStateException(" $lastTimeStamp $timestamp ${lastTimeStamp-timestamp} ")
|
||||
}
|
||||
if (timestamp == lastTimeStamp) {
|
||||
sequenceId++
|
||||
|
@ -46,7 +45,7 @@ open class SnowflakeIdGenerateService(private val baseTime: Long) : IdGenerateSe
|
|||
sequenceId = 0
|
||||
}
|
||||
lastTimeStamp = timestamp
|
||||
return@withLock (timestamp - baseTime).shl(22).or(1L.shl(12)).or(sequenceId.toLong())
|
||||
return@withLock (timestamp - baseTime).shl(22).or(1L.shl(12)).or(sequenceId)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,7 +76,7 @@ open class SnowflakeIdGenerateService(private val baseTime: Long) : IdGenerateSe
|
|||
override fun hashCode(): Int {
|
||||
var result = baseTime.hashCode()
|
||||
result = 31 * result + lastTimeStamp.hashCode()
|
||||
result = 31 * result + sequenceId
|
||||
result = 31 * result + sequenceId.hashCode()
|
||||
result = 31 * result + mutex.hashCode()
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -104,7 +104,9 @@ create table if not exists media
|
|||
"type" varchar(100) not null,
|
||||
blurhash varchar(255) null,
|
||||
mime_type varchar(255) not null,
|
||||
description varchar(4000) null
|
||||
description varchar(4000) null,
|
||||
actor_id bigint not null,
|
||||
constraint fk_media_actor_id__id foreign key (actor_id) references actors (id) on delete restrict on update restrict
|
||||
);
|
||||
|
||||
alter table actors
|
||||
|
|
|
@ -2,17 +2,17 @@
|
|||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%.15t] %highlight{%-5level} %logger{36} - %msg%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="DEBUG">
|
||||
<Root level="INFO">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
<Logger name="dev.usbharu.owl.broker.service.QueuedTaskAssignerImpl" level="TRACE"/>
|
||||
<!-- <Logger name="org.mongodb.driver.cluster" level=""/>-->
|
||||
<Logger name="org.mongodb.driver.cluster" level="INFO"/>
|
||||
<Logger name="org.apache.tomcat.util.net.NioEndpoint" level="INFO"/>
|
||||
<Logger name="Exposed" level="DEBUG"/>
|
||||
<!-- <Logger name="Exposed" level="DEBUG"/>-->
|
||||
<Logger name="sun.rmi" level="INFO"/>
|
||||
<Logger name="javax.management.remote.rmi" level="INFO"/>
|
||||
</Loggers>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
<div th:replace="fragments-timeline :: simple-timline(${timeline},'/home')"></div>
|
||||
<div th:replace="~{fragments-timeline :: simple-timline(${timeline},'/home')}"></div>
|
||||
</noscript>
|
||||
</body>
|
||||
</html>
|
|
@ -20,24 +20,24 @@
|
|||
<body>
|
||||
<noscript>
|
||||
<th:block th:if=" ${post.reply != null}">
|
||||
<th:block th:replace="fragments-post :: single-simple-post(${post.reply})"></th:block>
|
||||
<th:block th:replace="~{fragments-post :: single-simple-post(${post.reply})}"></th:block>
|
||||
<hr>
|
||||
</th:block>
|
||||
<main>
|
||||
<p th:if="${post.pureRepost}" th:text="#{post.repost-by(${post.actor.name})}">Repost by user</p>
|
||||
<th:block th:unless="${post.pureRepost}">
|
||||
<th:block th:replace="fragments-post :: single-simple-post(${post})"></th:block>
|
||||
<th:block th:replace="fragments-post :: single-post-controller(${post})"></th:block>
|
||||
<th:block th:replace="~{fragments-post :: single-simple-post(${post})}"></th:block>
|
||||
<th:block th:replace="~{fragments-post :: single-post-controller(${post})}"></th:block>
|
||||
</th:block>
|
||||
<th:block th:if="${post.pureRepost}">
|
||||
<th:block th:replace="fragments-post :: single-simple-post(${post.repost})"></th:block>
|
||||
<th:block th:replace="fragments-post :: single-post-controller(${post.repost})"></th:block>
|
||||
<th:block th:replace="~{fragments-post :: single-simple-post(${post.repost})}"></th:block>
|
||||
<th:block th:replace="~{fragments-post :: single-post-controller(${post.repost})}"></th:block>
|
||||
</th:block>
|
||||
|
||||
</main>
|
||||
<th:block th:if="${post.repost != null && !post.pureRepost}">
|
||||
<hr>
|
||||
<th:block th:replace="fragments-post :: single-simple-post(${post.repost})"></th:block>
|
||||
<th:block th:replace="={fragments-post :: single-simple-post(${post.repost})}"></th:block>
|
||||
<cite th:text="${post.repost.apId}"></cite>
|
||||
</th:block>
|
||||
</noscript>
|
||||
|
|
|
@ -1,28 +1,22 @@
|
|||
package dev.usbharu.hideout.core.infrastructure.other
|
||||
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class TwitterSnowflakeIdGenerateServiceTest {
|
||||
@Test
|
||||
fun noDuplicateTest() = runBlocking {
|
||||
val mutex = Mutex()
|
||||
val mutableListOf = mutableListOf<Long>()
|
||||
coroutineScope {
|
||||
repeat(500000) {
|
||||
launch(Dispatchers.IO) {
|
||||
val id = TwitterSnowflakeIdGenerateService.generateId()
|
||||
mutex.withLock {
|
||||
mutableListOf.add(id)
|
||||
}
|
||||
}
|
||||
|
||||
val mutableListOf = coroutineScope {
|
||||
(1..10000).map {
|
||||
async {
|
||||
TwitterSnowflakeIdGenerateService.generateId()
|
||||
}
|
||||
}.awaitAll()
|
||||
}
|
||||
|
||||
assertEquals(0, mutableListOf.size - mutableListOf.toSet().size)
|
||||
|
|
Loading…
Reference in New Issue