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

fix(core): Fix collection findBySlug issue2395 #2480

Conversation

ttournie
Copy link
Contributor

Fix the : #2395 issue.

Return the first found collection matching the findBySlug criteria.

To Test :

  1. Create 2 channel
  2. Create a collection with slug 'test' in the first channel
  3. Create a collection with the same slug the the other channel
  4. Go to the admin-api playground (or shop-api).
  5. Use the collection query with the header set to the first channel token -> you get the collection of this channel
  6. Do the same with the header set to the other channel -> you should get the other collection (the one corresponding to the channel in the header).

@netlify
Copy link

netlify bot commented Oct 23, 2023

Deploy Preview for effervescent-donut-4977b2 ready!

Name Link
🔨 Latest commit c49e675
🔍 Latest deploy log https://app.netlify.com/sites/effervescent-donut-4977b2/deploys/6540cc7bdb841b00080545d1
😎 Deploy Preview https://deploy-preview-2480--effervescent-donut-4977b2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Co-authored-by: Gautier Darchen <darchen.gautier@gmail.com>
@michaelbromley
Copy link
Member

Thanks for both the issue report and the fix! I just tried it out locally and it does indeed solve the issue. However, I was a little concerned about the fact that this solution has to make multiple this.findOne() calls in a for loop. I can imagine that in certain cases where a lot of languages are used, this may have a negative perf impact.

I found that we can avoid this by directly asserting the channel in the initial query to get the translations a the start of the method. It would look like this:

const translations = await this.connection.getRepository(ctx, CollectionTranslation).find({
    relations: ['base'],
    where: {
        slug,
        base: {
            channels: {
                id: ctx.channelId,
            },
        },
    },
});

Unless I'm missing some issue with doing it this way, it seems preferable.

@ttournie
Copy link
Contributor Author

Oh sure, I did not know you could put a where constraint on the base channels Id like that. So if this works, it's better, yes !

@michaelbromley michaelbromley merged commit 894ace7 into vendure-ecommerce:master Nov 1, 2023
14 checks passed
@michaelbromley
Copy link
Member

Thanks!

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.

3 participants