Upgrade to Pro — share decks privately, control downloads, hide ads and more …

なにも考えずClean ArchitectureでExposedを使ったらパフォーマンス...

kaonash
April 05, 2021

なにも考えずClean ArchitectureでExposedを使ったらパフォーマンスで地獄を見た話

kaonash

April 05, 2021
Tweet

More Decks by kaonash

Other Decks in Programming

Transcript

  1. SELF INTRODUCTION • ਗ਼ਫݦ(@kaonash_ ) • Lead Software Engineer &

    PdM & ΤϯδχΞ૊৫ߏங etc… @ UPSIDE R • Ҡॅ͍ͨ͠ܥΤϯδχΞʢ2022೥ɺ௕໺ʹҠॅ༧ఆʣ • Love: ୌ / Kitkat / Kotlin
  2. WHAT IS • Pure KotlinͷORMϑϨʔϜϫʔΫ • JetBrains੡ • 2छྨͷσʔλΞΫηεํ๏ •

    λΠϓηʔϑʹSQLͬΆ͘ΫΤϦΛ૊ΈཱͯΒΕΔDSL AP I • DAO(Data Access Object)Λ࢖͏DAO API
  3. ࠓճαϯϓϧͰ࢖͏ςʔϒϧΛఆٛ object BillTable : LongIdTable("bills") { val name = varchar("name",

    128 ) } object BillStatusTable : LongIdTable("bill_status") { val billId = reference("bill_id", BillTable ) val status = enumerationByName("status", 20, BillStatus::class ) val startAt = datetime("start_at").defaultExpression(CurrentDateTime() ) } billsςʔϒϧ΁ͷ֎෦ΩʔΛදݱ
  4. DAO APIΛ࢖͏৔߹͸ENTITY(DAO)΋ఆٛ class BillEntity(id: EntityID<Long>) : LongEntity(id) { companion object

    : LongEntityClass<BillEntity>(BillTable ) var name by BillTable.nam e val statusHistory by BillStatusEntity.referrersOn ( column = BillStatusTable.bill , cache = tru e ) } class BillStatusEntity(id: EntityID<Long>) : LongEntity(id) { companion object : LongEntityClass<BillStatusEntity>(BillStatusTable ) var bill by BillStatusTable.bil l var status by BillStatusTable.statu s var startAt by BillStatusTable.startA t } referrersOnΛ࢖͏͜ͱͰbill_statusςʔϒϧͷσʔλ΋ҰॹʹऔΕΔʂ
  5. ٧Ίସ͑Ε͹͑͑΍ͳ͍ͷ data class Bill ( val name: String , val

    statusHistory: List<BillStatus > ) data class BillStatus ( val status: String , val startAt: DateTime , ) ————————————————————————————————————————————————————————————————— — return BillEntity.all().map { bill - > Bill ( name = bill.name , statusHistory = bill.statusHistory.map { status - > BillStatus(status = status.status.name, startAt = status.startAt ) } ) }
  6. ղܾࡦɿEager LoadingΛ࢖͏ BillEntity.all().with(BillEntity::statusHistory).map { bill - > Bill ( name

    = bill.name , statusHistory = bill.statusHistory.map { status - > BillStatus(status = status.status.name, startAt = status.startAt ) } ) }.forEach { println(it) } ͜ͷ࣌఺Ͱ·ͱΊͯಡΈࠐΜͰ͘ΕΔʂ
  7. ஫ҙ఺ɿEntityఆٛ࣌ʹcache=trueʹ͓ͯ͠ ͔ͳ͍ͱ݁ہେྔͷΫΤϦ͕౤͛ΒΕΔ class BillEntity(id: EntityID<Long>) : LongEntity(id) { companion object

    : LongEntityClass<BillEntity>(BillTable ) var name by BillTable.nam e val statusHistory by BillStatusEntity.referrersOn ( column = BillStatusTable.bill , cache = fals e ) } ͜ΕͰಉ͡ॲཧΛ࣮ߦ͢Δͱɾɾɾ