Skip to content

Skip events on identical whitelist and config pushes#597

Open
kayjoosten wants to merge 1 commit into
feature/issue-583-email-templates-to-diskfrom
feature/issue-587-idempotent-event-stream-pushes
Open

Skip events on identical whitelist and config pushes#597
kayjoosten wants to merge 1 commit into
feature/issue-583-email-templates-to-diskfrom
feature/issue-587-idempotent-event-stream-pushes

Conversation

@kayjoosten

Copy link
Copy Markdown
Contributor

Summary

  • Add InstitutionCollection::equals() for order-independent comparison
  • Guard Whitelist::replaceAll() — no WhitelistReplacedEvent if content unchanged
  • Guard Configuration::update() — no events if decoded config unchanged
  • InstitutionConfiguration already had correct equality guards per-field; no change needed

Why

With manage pushing config hundreds of times per day (per OpenConext/OpenConext-manage#627), all three replace endpoints (/management/whitelist/replace, /management/configuration, /management/institution-configuration) were adding events on every push regardless of whether anything changed.

Test plan

  • Unit tests added for whitelist and config idempotent push scenarios
  • Behat tests added in devconf (mw_idempotent_push.feature) to verify event stream count does not grow on duplicate pushes

Closes #587

Note: This PR targets feature/issue-583-email-templates-to-disk (PR #595) as its base, since it depends on the clean Configuration::update() from that branch. It should be rebased onto main after #595 merges.

@kayjoosten kayjoosten linked an issue Jun 12, 2026 that may be closed by this pull request
@kayjoosten kayjoosten force-pushed the feature/issue-587-idempotent-event-stream-pushes branch from c95a0c3 to 0a423f6 Compare June 12, 2026 08:49
Comment thread src/Surfnet/Stepup/Identity/Whitelist.php Outdated
@kayjoosten kayjoosten force-pushed the feature/issue-587-idempotent-event-stream-pushes branch from f97b718 to 7291a43 Compare June 15, 2026 08:50

public function replaceAll(InstitutionCollection $institutionCollection): void
{
if ($this->whitelist->equals($institutionCollection)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pipeline fails: Cannot call method equals() on Surfnet\Stepup\Identity\Collection\InstitutionCollection|null.

*/
private function deepKsort(array $array): array
{
ksort($array);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear here what the keys actually are? Are they ints? If so, is the array already sorted.

If the actual data types are known/determined, consider adding proper type hints instead of mixed.

@kayjoosten kayjoosten force-pushed the feature/issue-583-email-templates-to-disk branch from f0e1fd0 to 4b43553 Compare June 17, 2026 12:16
@kayjoosten kayjoosten force-pushed the feature/issue-587-idempotent-event-stream-pushes branch from 7291a43 to 9a015ea Compare June 17, 2026 12:19
Prior to this change, Whitelist::replaceAll() and Configuration::update()
always emitted events regardless of whether the content had changed.
With manage pushing configuration hundreds of times per day, this caused
unbounded event stream growth on no-op pushes.

This change adds idempotency guards to both methods so events are only
emitted when content actually changes. Config comparison is normalised
with recursive ksort to be key-order-insensitive. A new
InstitutionCollection::equals() method handles order-independent
institution set comparison. InstitutionConfiguration already had correct
equality guards and required no changes.

Closes #587
@kayjoosten kayjoosten force-pushed the feature/issue-587-idempotent-event-stream-pushes branch from d395cb9 to cd06292 Compare June 17, 2026 12:56
@kayjoosten kayjoosten requested a review from johanib June 17, 2026 13:01
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.

Validate middleware eventstream behaviour

2 participants