Skip to content

added userset weight to edge#509

Merged
yissellokta merged 2 commits intomainfrom
fix/userset-weight
Nov 7, 2025
Merged

added userset weight to edge#509
yissellokta merged 2 commits intomainfrom
fix/userset-weight

Conversation

@yissellokta
Copy link
Copy Markdown
Contributor

@yissellokta yissellokta commented Nov 6, 2025

Description

What problem is being solved?

Surfacing the edge weight for userset

How is it being solved?

What changes are made to solve it?

References

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Summary by CodeRabbit

  • Refactor

    • Renamed node weight accessor from GetWeight() to GetNodeWeight() for improved API clarity.
  • New Features

    • Added GetEdgeWeight() method to compute and retrieve edge weights with enhanced support for edge-specific weight handling.

@yissellokta yissellokta requested a review from a team as a code owner November 6, 2025 18:11
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Nov 6, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request refactors the weighted graph API by renaming the node weight accessor from GetWeight() to GetNodeWeight(), introducing a new GetEdgeWeight() method for edge weights, adding an internal helper calculateUsersetWeightInEdge(), and consolidating edge weight update logic throughout the userset weight calculation flow.

Changes

Cohort / File(s) Summary
Implementation
pkg/go/graph/weighted_graph.go
Renamed GetWeight() to GetNodeWeight() for node-level weight access; added new public method GetEdgeWeight() with support for SpecificTypeAndRelation key handling and fallback logic; introduced internal helper calculateUsersetWeightInEdge() to centralize edge weight updates; refactored weight propagation in calculateUsersetWeights and related paths to use the new edge-oriented calculation pathway instead of inlining weight-update logic.
Test Coverage
pkg/go/graph/weighted_graph_userset_test.go
Updated all test calls from GetWeight() to GetNodeWeight(); added new assertions for GetEdgeWeight() on specific edges; expanded test model with new public relations and member definitions; adjusted expected weight values and existence checks to reflect the new API surface.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Key focus areas:
    • Verification that GetEdgeWeight() correctly handles SpecificTypeAndRelation keys, edge-specific weights, and fallback delegations to userset weight computation
    • Validation of the new calculateUsersetWeightInEdge() helper's integration into weight propagation flows and consistency with prior inline logic
    • Confirmation that all refactored call sites in weight calculation functions preserve original behavior while routing through the new edge-oriented pathway
    • Test coverage completeness for both node and edge weights across various graph scenarios

Possibly related PRs

  • openfga/language#505: Introduces userset-weight logic in weighted graph machinery; this PR extends that foundation by refactoring and centralizing edge weight calculations through the new GetEdgeWeight() and calculateUsersetWeightInEdge() pathway.

Suggested reviewers

  • adriantam
  • elbuo8
  • jpadilla

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: exposing edge weight for userset by renaming GetWeight to GetNodeWeight and adding GetEdgeWeight.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f8f255 and fb21717.

📒 Files selected for processing (2)
  • pkg/go/graph/weighted_graph.go (4 hunks)
  • pkg/go/graph/weighted_graph_userset_test.go (7 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
pkg/go/graph/weighted_graph.go (2)
pkg/go/graph/weighted_graph_node.go (1)
  • WeightedAuthorizationModelNode (18-27)
pkg/go/graph/weighted_graph_edge.go (3)
  • WeightedAuthorizationModelEdge (58-76)
  • DirectEdge (11-11)
  • TTUEdge (21-21)
pkg/go/graph/weighted_graph_userset_test.go (1)
pkg/go/graph/weighted_graph.go (1)
  • Infinite (11-11)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)

Comment thread pkg/go/graph/weighted_graph.go Outdated
Comment thread pkg/go/graph/weighted_graph.go Outdated
@yissellokta yissellokta enabled auto-merge November 6, 2025 21:17
@yissellokta yissellokta added this pull request to the merge queue Nov 7, 2025
Merged via the queue into main with commit 4fcf920 Nov 7, 2025
10 checks passed
@yissellokta yissellokta deleted the fix/userset-weight branch November 7, 2025 14:35
@coderabbitai coderabbitai bot mentioned this pull request Nov 13, 2025
4 tasks
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.

2 participants