feat: add batch setting operations#161
Open
memleakd wants to merge 2 commits intocodeigniter4:developfrom
Open
feat: add batch setting operations#161memleakd wants to merge 2 commits intocodeigniter4:developfrom
memleakd wants to merge 2 commits intocodeigniter4:developfrom
Conversation
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Hello! This PR proposes adding explicit batch APIs for storing and forgetting multiple settings in one call:
Settings::setMany()Settings::forgetMany()This is offered as a small, generic addition for maintainers to review and adjust. The goal is to support applications and modules that already have a related group of settings to update, without requiring callers to issue separate
set()orforget()calls for each item.This can be useful for common cases like saving configuration forms, applying setup defaults, updating module preferences, importing settings, or resetting a group of related options. It also gives handlers a clear extension point for optimizing grouped writes while keeping existing handler behavior compatible.
Why
The limitations documentation notes that immediate writes can result in multiple database queries or file writes when several settings are changed in one request.
With this PR, callers can group those operations directly:
This is also intended to complement the deferred writes work from #154. Deferred writes optimize multiple
set()/forget()calls across the request lifecycle, while these methods provide an explicit API when the caller already has a batch of related changes.Behavior
The new APIs follow the same behavior as repeated calls to
set()andforget():Class.propertysyntaxThey also respect the current
deferWritessetting:deferWritesis disabled, supported handlers persist the batch immediatelydeferWritesis enabled, batch calls are queued and persisted duringpost_systemHandler Support
BaseHandlerincludes defaultsetMany()andforgetMany()implementations that call the existingset()andforget()methods for each item. Existing custom handlers keep working through this fallback.Handlers can still override the batch methods when they can persist more efficiently:
DatabaseHandlergroups batch inserts, updates, and deletesFileHandlergroups changes per class/context fileTests and Docs
This PR adds tests for the public API, context-aware batch operations, duplicate key handling, database/file handler batch persistence, and deferred batch writes.
The user guide is updated with examples and clarifies how explicit batch APIs relate to deferred writes.
Checklist: