This repository was archived by the owner on Dec 5, 2025. It is now read-only.
refactor: enums to use CaseInsensitiveMixin for has_value#873
Closed
allrob23 wants to merge 3 commits intoOpenCTI-Platform:masterfrom
Closed
refactor: enums to use CaseInsensitiveMixin for has_value#873allrob23 wants to merge 3 commits intoOpenCTI-Platform:masterfrom
allrob23 wants to merge 3 commits intoOpenCTI-Platform:masterfrom
Conversation
|
Thanks @allrob23 for your contribution, we're going to look at it ! |
Member
|
There is a conflit to resolve here. |
|
Thank you for your contribution, but we need you to sign your commits. Please see https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits |
xfournet
approved these changes
Oct 9, 2025
Member
|
Everything looks good :) However, we need the signature of the commit please. |
Member
|
Hello, this repository has been moved to All PR here in this repository will be closed, if you still need it, please reopen on https://github.com/OpenCTI-Platform/opencti |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Proposed changes
CaseInsensitiveMixinto improve code reuse for case-insensitive value checking across Enum classes.StixCyberObservableTypes,IdentityTypes,ThreatActorTypes,LocationTypes,ContainerTypes,StixMetaTypes, andMultipleRefRelationshipto remove duplicatedhas_valuefunction logic.has_valueto use a set (O(1) lookup) instead of a list (O(N) lookup) and added caching forlower_valuesto avoid recreating it on every call.This change follows the DRY principle by centralizing case-insensitive checks in a single mixin, making the code cleaner and easier to maintain. It's not a major performance optimization, but it's a nice improvement. I’ve included a benchmark below to show the results.
Benchmark code and results:
code: https://gist.github.com/allrob23/03382afaffec1a31472ed6fa90fdeb52
Result
Original: 0.004698 seconds
Refactored: 0.000227 seconds
Checklist
Further comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...