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

Improve performance of CSAF ingestion #458

Merged
merged 4 commits into from
Jun 26, 2024

Conversation

ctron
Copy link
Contributor

@ctron ctron commented Jun 26, 2024

With the performance test, this improves the import time from ~470ms to ~240ms

@ctron ctron requested a review from bobmcwhirter June 26, 2024 11:47
@ctron ctron enabled auto-merge June 26, 2024 12:11
@ctron
Copy link
Contributor Author

ctron commented Jun 26, 2024

Also see: #456

impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_index(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, thanks!

@@ -31,7 +31,7 @@ pub enum Version {
}

impl VersionInfo {
fn into_active_model(self) -> version_range::ActiveModel {
pub fn into_active_model(self) -> version_range::ActiveModel {
Copy link
Contributor

Choose a reason for hiding this comment

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

bonus points: if you can understand why implementing IntoActiveModel caused rustc to complain about duplicate impls, that'd be lovely. There was a trait I could use, but I couldn't make rustc happy, hence this one-off fn.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That one was a bit weird, it seems to be coming from the blanket implementation of that trait in seaorm:

impl<A> IntoActiveModel<A> for A
where
    A: ActiveModelTrait,
{
    fn into_active_model(self) -> A {
        self
    }
}

Which basically means that you can't implement IntoActiveModel for anything that should become an ActiveModel. Which feels like an API bug to me.

It also doesn't seem possible to implement From or Into for that case due to similar conflicts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, that's not correct. Because in this case A would be VersionInfo, which doesn't implement ActiveModelTrait. And the compiler complains about impl sea_orm::IntoActiveModel<trustify_entity::version_range::ActiveModel> for <trustify_entity::version_range::Entity as sea_orm::EntityTrait>::Model being the conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I give up on the bonus points and leave it a mystery.

package,
status,
info: VersionInfo {
scheme: "generic".to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

not your problem, just noting: there's a few schemes which happen to match the purl type so we could avoid generic perhaps, if we know it's a python, or maven, or rust (semver) type.

for ps in &self.entries {
// ensure a correct status, and get id
if let Entry::Vacant(entry) = checked.entry(ps.status) {
entry.insert(Self::check_status(ps.status, connection).await?);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean status rows can be implicitly added upon first sighting? I think that's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, that just inserts it into the hash map. The idea is to look it up only once, cache the status.id and re-use it a bit further down the function. Versus: looking it up for each entry.

@ctron ctron added this pull request to the merge queue Jun 26, 2024
Merged via the queue into trustification:main with commit 47be914 Jun 26, 2024
1 check passed
@ctron ctron deleted the feature/perf_1 branch June 26, 2024 18:49
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