Merge pull request #567 from usbharu/refactor

ログを改善
This commit is contained in:
usbharu 2024-08-24 15:49:15 +09:00 committed by GitHub
commit dd9749a536
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 50 additions and 36 deletions

View File

@ -30,7 +30,8 @@ abstract class AbstractApplicationService<T : Any, R>(
val response = transaction.transaction<R> { val response = transaction.transaction<R> {
internalExecute(command, principal) internalExecute(command, principal)
} }
logger.info("SUCCESS ${command::class.simpleName}")
logger.info("SUCCESS $command $response")
response response
} catch (e: CancellationException) { } catch (e: CancellationException) {
logger.debug("Coroutine canceled", e) logger.debug("Coroutine canceled", e)

View File

@ -42,6 +42,16 @@ class UserDetail(
} }
override fun hashCode(): Int = id.hashCode() 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 { companion object {
@Suppress("LongParameterList") @Suppress("LongParameterList")

View File

@ -17,4 +17,8 @@
package dev.usbharu.hideout.core.domain.model.userdetails package dev.usbharu.hideout.core.domain.model.userdetails
@JvmInline @JvmInline
value class UserDetailHashedPassword(val password: String) value class UserDetailHashedPassword(val password: String) {
override fun toString(): String {
return "[MASKED]"
}
}

View File

@ -17,4 +17,8 @@
package dev.usbharu.hideout.core.domain.model.userdetails package dev.usbharu.hideout.core.domain.model.userdetails
@JvmInline @JvmInline
value class UserDetailId(val id: Long) value class UserDetailId(val id: Long) {
override fun toString(): String {
return "UserDetailId(id=$id)"
}
}

View File

@ -24,9 +24,9 @@ import java.time.Instant
@Suppress("MagicNumber") @Suppress("MagicNumber")
open class SnowflakeIdGenerateService(private val baseTime: Long) : IdGenerateService { open class SnowflakeIdGenerateService(private val baseTime: Long) : IdGenerateService {
var lastTimeStamp: Long = -1 private var lastTimeStamp: Long = -1
var sequenceId: Int = 0 private var sequenceId: Long = 0
val mutex = Mutex() private val mutex = Mutex()
@Throws(IllegalStateException::class) @Throws(IllegalStateException::class)
override suspend fun generateId(): Long { override suspend fun generateId(): Long {
@ -34,7 +34,6 @@ open class SnowflakeIdGenerateService(private val baseTime: Long) : IdGenerateSe
var timestamp = getTime() var timestamp = getTime()
if (timestamp < lastTimeStamp) { if (timestamp < lastTimeStamp) {
timestamp = wait(timestamp) timestamp = wait(timestamp)
// throw IllegalStateException(" $lastTimeStamp $timestamp ${lastTimeStamp-timestamp} ")
} }
if (timestamp == lastTimeStamp) { if (timestamp == lastTimeStamp) {
sequenceId++ sequenceId++
@ -46,7 +45,7 @@ open class SnowflakeIdGenerateService(private val baseTime: Long) : IdGenerateSe
sequenceId = 0 sequenceId = 0
} }
lastTimeStamp = timestamp 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 { override fun hashCode(): Int {
var result = baseTime.hashCode() var result = baseTime.hashCode()
result = 31 * result + lastTimeStamp.hashCode() result = 31 * result + lastTimeStamp.hashCode()
result = 31 * result + sequenceId result = 31 * result + sequenceId.hashCode()
result = 31 * result + mutex.hashCode() result = 31 * result + mutex.hashCode()
return result return result
} }

View File

@ -101,10 +101,12 @@ create table if not exists media
url varchar(255) not null unique, url varchar(255) not null unique,
remote_url varchar(255) null unique, remote_url varchar(255) null unique,
thumbnail_url varchar(255) null unique, thumbnail_url varchar(255) null unique,
"type" varchar(100) not null, "type" varchar(100) not null,
blurhash varchar(255) null, blurhash varchar(255) null,
mime_type varchar(255) not 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 alter table actors

View File

@ -2,17 +2,17 @@
<Configuration status="WARN"> <Configuration status="WARN">
<Appenders> <Appenders>
<Console name="Console" target="SYSTEM_OUT"> <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> </Console>
</Appenders> </Appenders>
<Loggers> <Loggers>
<Root level="DEBUG"> <Root level="INFO">
<AppenderRef ref="Console"/> <AppenderRef ref="Console"/>
</Root> </Root>
<Logger name="dev.usbharu.owl.broker.service.QueuedTaskAssignerImpl" level="TRACE"/> <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="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="sun.rmi" level="INFO"/>
<Logger name="javax.management.remote.rmi" level="INFO"/> <Logger name="javax.management.remote.rmi" level="INFO"/>
</Loggers> </Loggers>

View File

@ -6,7 +6,7 @@
</head> </head>
<body> <body>
<noscript> <noscript>
<div th:replace="fragments-timeline :: simple-timline(${timeline},'/home')"></div> <div th:replace="~{fragments-timeline :: simple-timline(${timeline},'/home')}"></div>
</noscript> </noscript>
</body> </body>
</html> </html>

View File

@ -20,24 +20,24 @@
<body> <body>
<noscript> <noscript>
<th:block th:if=" ${post.reply != null}"> <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> <hr>
</th:block> </th:block>
<main> <main>
<p th:if="${post.pureRepost}" th:text="#{post.repost-by(${post.actor.name})}">Repost by user</p> <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:unless="${post.pureRepost}">
<th:block th:replace="fragments-post :: single-simple-post(${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:replace="~{fragments-post :: single-post-controller(${post})}"></th:block>
</th:block> </th:block>
<th:block th:if="${post.pureRepost}"> <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-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-post-controller(${post.repost})}"></th:block>
</th:block> </th:block>
</main> </main>
<th:block th:if="${post.repost != null && !post.pureRepost}"> <th:block th:if="${post.repost != null && !post.pureRepost}">
<hr> <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> <cite th:text="${post.repost.apId}"></cite>
</th:block> </th:block>
</noscript> </noscript>

View File

@ -1,28 +1,22 @@
package dev.usbharu.hideout.core.infrastructure.other 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.coroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking 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.Assertions.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class TwitterSnowflakeIdGenerateServiceTest { class TwitterSnowflakeIdGenerateServiceTest {
@Test @Test
fun noDuplicateTest() = runBlocking { fun noDuplicateTest() = runBlocking {
val mutex = Mutex()
val mutableListOf = mutableListOf<Long>() val mutableListOf = coroutineScope {
coroutineScope { (1..10000).map {
repeat(500000) { async {
launch(Dispatchers.IO) { TwitterSnowflakeIdGenerateService.generateId()
val id = TwitterSnowflakeIdGenerateService.generateId()
mutex.withLock {
mutableListOf.add(id)
}
} }
} }.awaitAll()
} }
assertEquals(0, mutableListOf.size - mutableListOf.toSet().size) assertEquals(0, mutableListOf.size - mutableListOf.toSet().size)