Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backend] Use join map to avoid duplicate join #1619

Merged
merged 3 commits into from
Oct 15, 2024
Merged

Conversation

RomuDeuxfois
Copy link
Member

@RomuDeuxfois RomuDeuxfois commented Oct 4, 2024

Proposed changes

  • Use join map to avoid duplicate join

Related issues

Query without filters:

select
        distinct s1_0.scenario_id,
        s1_0.scenario_name,
        s1_0.scenario_severity,
        s1_0.scenario_category,
        s1_0.scenario_recurrence,
        s1_0.scenario_updated_at,
        array_remove(array_agg(t1_0.tag_id), null),
        array_union_agg(ic1_0.injector_contract_platforms) 
    from
        scenarios s1_0 
    left join
        scenarios_tags t1_0 
            on s1_0.scenario_id=t1_0.scenario_id 
    left join
        injects i1_0 
            on s1_0.scenario_id=i1_0.inject_scenario 
    left join
        injectors_contracts ic1_0 
            on ic1_0.injector_contract_id=i1_0.inject_injector_contract 
    where
        1=1 
        and 1=1 
    group by
        1 
    order by
        6 desc 
    offset
        ? rows 
    fetch
        first ? rows only

Query with filters: category + kill chain phases + tags

    select
        distinct s1_0.scenario_id,
        s1_0.scenario_name,
        s1_0.scenario_severity,
        s1_0.scenario_category,
        s1_0.scenario_recurrence,
        s1_0.scenario_updated_at,
        array_remove(array_agg(t1_0.tag_id), null),
        array_union_agg(ic1_0.injector_contract_platforms) 
    from
        scenarios s1_0 
    left join
        scenarios_tags t1_0 
            on s1_0.scenario_id=t1_0.scenario_id 
    left join
        injects i1_0 
            on s1_0.scenario_id=i1_0.inject_scenario 
    left join
        injectors_contracts ic1_0 
            on ic1_0.injector_contract_id=i1_0.inject_injector_contract 
    left join
        (injectors_contracts_attack_patterns ap1_0 
    join
        attack_patterns ap1_1 
            on ap1_1.attack_pattern_id=ap1_0.attack_pattern_id) 
        on ic1_0.injector_contract_id=ap1_0.injector_contract_id 
    left join
        attack_patterns_kill_chain_phases kcp1_0 
            on ap1_1.attack_pattern_id=kcp1_0.attack_pattern_id 
    where
        1=1 
        and 1=1 
        and 1=1 
        and 1=1 
    group by
        1 
    order by
        6 desc 
    offset
        ? rows 
    fetch
        first ? rows only
Hibernate: 
    select
        count(distinct s1_0.scenario_id) 
    from
        scenarios s1_0 
    where
        1=1 
        and 1=1 
        and 1=1 
        and 1=1

@github-actions github-actions bot added the filigran team use to identify PR from the Filigran team label Oct 4, 2024
Copy link

codecov bot commented Oct 4, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 25 lines in your changes missing coverage. Please review.

Project coverage is 32.45%. Comparing base (db39652) to head (3f16ae7).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
.../src/main/java/io/openbas/service/TeamService.java 0.00% 7 Missing ⚠️
.../main/java/io/openbas/rest/user/PlayerService.java 0.00% 4 Missing ⚠️
.../java/io/openbas/service/AtomicTestingService.java 0.00% 4 Missing ⚠️
...java/io/openbas/rest/inject/ExerciseInjectApi.java 0.00% 3 Missing ⚠️
.../main/java/io/openbas/service/ScenarioService.java 82.35% 3 Missing ⚠️
...ain/java/io/openbas/rest/exercise/ExerciseApi.java 0.00% 2 Missing ⚠️
.../io/openbas/rest/scenario/ScenarioExerciseApi.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1619      +/-   ##
============================================
+ Coverage     32.36%   32.45%   +0.09%     
- Complexity     1508     1510       +2     
============================================
  Files           545      545              
  Lines         14119    14134      +15     
  Branches        844      843       -1     
============================================
+ Hits           4569     4587      +18     
+ Misses         9336     9331       -5     
- Partials        214      216       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@RomuDeuxfois RomuDeuxfois marked this pull request as ready for review October 14, 2024 13:02
@savacano28
Copy link
Contributor

Tested ok

@RomuDeuxfois RomuDeuxfois merged commit e2de799 into master Oct 15, 2024
5 checks passed
@RomuDeuxfois RomuDeuxfois deleted the issue/1583-generic branch October 15, 2024 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filigran team use to identify PR from the Filigran team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants