-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Move caching from UserResponder to UserService #3064
Conversation
…save` in the `UserRepo`
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3064 +/- ##
===========================================
+ Coverage 11.74% 88.56% +76.81%
===========================================
Files 246 262 +16
Lines 22907 22553 -354
===========================================
+ Hits 2690 19973 +17283
+ Misses 20217 2580 -17637 ☔ View full report in Codecov by Sentry. |
webapi/src/main/scala/org/knora/webapi/store/cache/impl/CacheServiceLive.scala
Outdated
Show resolved
Hide resolved
case Some(user) => cacheService.putUser(user) | ||
case None => ZIO.unit | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps?
fromCache(id).flatMap {
_.map(ZIO.some(_)).getOrElse {
fromRepo(id).flatMap {
ZIO.foreach(_)(toUser(_).tap(cacheService.putUser(_)))
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we recently discussed that ZIO code often looks more idiomatic if optionality is moved to the E
channel. Maybe that could make it even nicer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh, I find this less readable.
How about:
fromCache(id).flatMap {
case Some(user) => ZIO.some(user)
case None => fromRepo(id).some.flatMap(toUser(_).tap(cacheService.putUser).asSomeError).unsome
}
case Some(user) => cacheService.putUser(user) | ||
case None => ZIO.unit | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we recently discussed that ZIO code often looks more idiomatic if optionality is moved to the E
channel. Maybe that could make it even nicer?
Pull Request Checklist
Task Description/Number
User
s intoUserService
invalidate user on everysave
in theUserRepo
PR Type
Basic requirements for bug fixes and features
Does this PR introduce a breaking change?
Does this PR change client-test-data?