Skip to content
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

Merged
merged 11 commits into from
Feb 27, 2024

Conversation

seakayone
Copy link
Contributor

@seakayone seakayone commented Feb 27, 2024

Pull Request Checklist

Task Description/Number

  • Move caching of Users into UserService invalidate user on every save in the UserRepo
  • Move findAllUsers from Responder to RestService

PR Type

  • build/chore: maintenance tasks (no production code change)
  • docs: documentation changes (no production code change)
  • feat: represents new features
  • fix: represents bug fixes
  • perf: performance improvements
  • refactor: represents production code refactoring
  • test: adding or refactoring tests (no production code change)

Basic requirements for bug fixes and features

  • Tests for the changes have been added
  • Docs have been added / updated

Does this PR introduce a breaking change?

  • Yes

Does this PR change client-test-data?

  • Yes

Copy link

linear bot commented Feb 27, 2024

@seakayone seakayone self-assigned this Feb 27, 2024
Copy link

codecov bot commented Feb 27, 2024

Codecov Report

Attention: Patch coverage is 96.05263% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 88.56%. Comparing base (eac5751) to head (b0360fd).
Report is 85 commits behind head on main.

Files Patch % Lines
...tore/cache/CacheServiceRequestMessageHandler.scala 33.33% 2 Missing ⚠️
...api/slice/admin/api/service/StoreRestService.scala 0.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@seakayone seakayone marked this pull request as ready for review February 27, 2024 10:49
@seakayone seakayone changed the title refactor: Move caching to UserService refactor: Move caching from UserResponder to UserService Feb 27, 2024
case Some(user) => cacheService.putUser(user)
case None => ZIO.unit
}
}
Copy link
Contributor

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(_)))
        }
      }
    }

Copy link
Contributor

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?

Copy link
Contributor Author

@seakayone seakayone Feb 27, 2024

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
}
}
Copy link
Contributor

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?

@seakayone seakayone merged commit 0484717 into main Feb 27, 2024
13 checks passed
@seakayone seakayone deleted the refactor/remove-UsersResponder-DEV-3291-2 branch February 27, 2024 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants