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> {
internalExecute(command, principal)
}
logger.info("SUCCESS ${command::class.simpleName}")
logger.info("SUCCESS $command $response")
response
} catch (e: CancellationException) {
logger.debug("Coroutine canceled", e)

View File

@ -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")

View File

@ -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]"
}
}

View File

@ -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)"
}
}

View File

@ -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
}

View File

@ -101,10 +101,12 @@ create table if not exists media
url varchar(255) not null unique,
remote_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,
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

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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)