Skip to content

Avoid useless SPARQL queries#1800

Merged
osma merged 16 commits intomainfrom
issue1799-avoid-useless-sparql-queries
Aug 26, 2025
Merged

Avoid useless SPARQL queries#1800
osma merged 16 commits intomainfrom
issue1799-avoid-useless-sparql-queries

Conversation

@osma
Copy link
Member

@osma osma commented Aug 20, 2025

Reasons for creating this PR

Skosmos performs a number of useless SPARQL queries, see #1799.

This PR reduces the number of unnecessary SPARQL queries, thereby increasing performance.

Benchmark results

(Note: These have been updated following the merge of #1796, which eliminated duplicate SPARQL queries using a cache - before the query cache was added, the differences were even more dramatic.)

On my local Skosmos installation, a global search query for "aaron"

  • before (main): took 3.3 seconds and resulted in 22 SPARQL queries
  • after (this PR): took 0.7 seconds and resulted in 2 SPARQL queries

Showing the concept page for "Aaron (Raamatun henkilö)"

  • before (main): took 2.7 seconds and resulted in 22 SPARQL queries
  • after (this PR): took 2.1 seconds and resulted in 16 SPARQL queries

Link to relevant issue(s), if any

Description of the changes in this PR

  • make it possible to limit the properties that Concept.getProperties() returns, avoiding the processing of properties that aren't shown on the search result page (and the SPARQL queries that would be triggered by that processing)
  • introduce an $allowExternal parameter for many getLabel() methods that, when set to false, avoids performing a SPARQL query in situations where it isn't really necessary (in a few cases, this replaces a similar preexisting $queryExVocabs parameter that was used inconsistently)
  • refactor Concept.getProperties() and Concept.getMappingProperties() a little bit, extracting helper methods that perform part of the work

Known problems or uncertainties in this PR

Unit test coverage is not 100% for the modified code. In particular, I haven't written unit tests for the parts of Concept.php that were refactored. However, this is not a regression - we didn't have such tests earlier.

It's possible that some special cases related to how information is displayed on search results or concept pages have been broken by the changes in the PR, but it's pretty difficult to tell. I've tried to test for tricky cases but I may well have missed something.

Checklist

  • phpUnit tests pass locally with my changes
  • I have added tests that show that the new code works, or tests are not relevant for this PR (e.g. only HTML/CSS changes)
  • The PR doesn't reduce accessibility of the front-end code (e.g. tab focus, scaling to different resolutions, use of .sr-only class, color contrast)
  • The PR doesn't introduce unintended code changes (e.g. empty lines or useless reindentation)

@osma osma self-assigned this Aug 20, 2025
@osma osma moved this to In progress in Skosmos 3.x Backlog Aug 20, 2025
@codecov
Copy link

codecov bot commented Aug 26, 2025

Codecov Report

❌ Patch coverage is 80.20833% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.73%. Comparing base (edcff22) to head (3054a71).

Files with missing lines Patch % Lines
src/model/Concept.php 77.92% 17 Missing ⚠️
src/model/ConceptMappingPropertyValue.php 90.90% 1 Missing ⚠️
src/model/ConceptPropertyValue.php 83.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1800      +/-   ##
============================================
- Coverage     71.06%   70.73%   -0.33%     
- Complexity     1647     1650       +3     
============================================
  Files            33       33              
  Lines          4320     4326       +6     
============================================
- Hits           3070     3060      -10     
- Misses         1250     1266      +16     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 26, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@osma osma changed the title WIP: Avoid useless SPARQL queries Avoid useless SPARQL queries Aug 26, 2025
@osma osma moved this from In progress to Needs review in Skosmos 3.x Backlog Aug 26, 2025
@osma osma marked this pull request as ready for review August 26, 2025 10:21
@osma osma requested a review from joelit August 26, 2025 10:21
@osma osma added this to the 3.0-beta.1 milestone Aug 26, 2025
Copy link
Contributor

@joelit joelit left a comment

Choose a reason for hiding this comment

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

LGTM! In certain cases this really cuts down on the number of generated queries.

@osma osma merged commit d8f0109 into main Aug 26, 2025
12 of 14 checks passed
@github-project-automation github-project-automation bot moved this from Needs review to Issue/PR closed in Skosmos 3.x Backlog Aug 26, 2025
@osma osma deleted the issue1799-avoid-useless-sparql-queries branch August 26, 2025 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Useless SPARQL queries for concept labels

2 participants