mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-09 17:23:22 +03:00
[PR #423] [MERGED] refactor: simplify app_config service and fix race conditions #807
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/pocket-id/pocket-id/pull/423
Author: @ItalyPaleAle
Created: 4/9/2025
Status: ✅ Merged
Merged: 4/10/2025
Merged by: @stonith404
Base:
main← Head:config-refactor📝 Commits (10+)
81a9643WIP314e3b0More WIPc3bb9a8More WIP2ed730aMore WIP2746f7bMore WIP39d3116Code compilesd5c3d7bInitial unit tests for app_config_service2992839More tests87e258cMore testsf96b390Load config from env when UI config is disabled📊 Changes
28 files changed (+1241 additions, -538 deletions)
View changed files
📝
.github/workflows/backend-linter.yml(+1 -1)📝
Dockerfile(+1 -1)📝
backend/go.mod(+1 -1)📝
backend/internal/bootstrap/bootstrap.go(+1 -0)📝
backend/internal/controller/app_config_controller.go(+14 -22)📝
backend/internal/controller/e2etest_controller.go(+1 -1)📝
backend/internal/controller/user_controller.go(+3 -3)📝
backend/internal/controller/webauthn_controller.go(+1 -1)📝
backend/internal/dto/app_config_dto.go(+1 -1)📝
backend/internal/job/ldap_job.go(+1 -1)📝
backend/internal/model/app_config.go(+152 -40)📝
backend/internal/model/app_config_test.go(+71 -2)📝
backend/internal/service/app_config_service.go(+308 -355)➕
backend/internal/service/app_config_service_test.go(+561 -0)📝
backend/internal/service/audit_log_service.go(+1 -1)📝
backend/internal/service/e2etest_service.go(+5 -9)📝
backend/internal/service/email_service.go(+17 -13)📝
backend/internal/service/jwt_service.go(+1 -1)📝
backend/internal/service/jwt_service_test.go(+18 -30)📝
backend/internal/service/ldap_service.go(+51 -46)...and 8 more files
📄 Description
Fixes #391
Fixes #407
As discussed with @stonith404 , this PR refactors the app_config service with the goals of greatly simplify the logic, and fixing race conditions.
There are significant performance improvements too, especially when updating config, as the number of database round-trips has been reduced to no more than 2 (currently, it's 2 per each key). API calls to retrieve config are also much faster as they return the data from memory only.
atomic.Pointer, which removes the risk of data races.PR includes extensive unit tests which use an in-memory SQLite database to validate the behavior of the service.
Note: I had to update to Go 1.24 to be able to use
testing.Context().🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.