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

(perf, refactor) Remove unnecessary code in Media subscription. #3558

Merged

Conversation

prinzdezibel
Copy link
Contributor

@prinzdezibel prinzdezibel commented Jan 23, 2018

Closes #3557

This ticket addresses:

  • cost of ownership (number of LOC), because of dead selector variable
  • performance , because it prevents unnecessary DDP roundtrips.

@mikemurray mikemurray self-requested a review January 23, 2018 22:32
@mikemurray
Copy link
Member

mikemurray commented Jan 23, 2018

@prinzdezibel This publication might still be used. Uploading a logo for the shop brand, unless that has been removed from shop settings, uses this publication.

Copy link
Member

@mikemurray mikemurray left a comment

Choose a reason for hiding this comment

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

Verified this publication is still required for the shop logo upload.

This publication may also be needed for some media documents under revision control.

reaction

@brent-hoover
Copy link
Collaborator

@prinzdezibel Please always include test instructions in every PR you submit

* CollectionFS - Image/Video Publication
* @params {Array} shops - array of current shop object
*/
Meteor.publish("Media", function (shops) {
Copy link
Collaborator

@brent-hoover brent-hoover Jan 24, 2018

Choose a reason for hiding this comment

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

As @mikemurray notes we still need brandAssets but I wonder if we still need all this code which seems like it just gets negated by

return Media.find({
 -    "metadata.type": "brandAsset"
 -  });

at the bottom?

Do we still need this for reactivity or is this handled in the Products publication?

Copy link
Contributor

Choose a reason for hiding this comment

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

@zenweasel @mikemurray It does seem that this publication could be simplified significantly.

@prinzdezibel
Copy link
Contributor Author

Thanks for the hint with the brand asset, @mikemurray. I've been thinking hard and could not imagine a place where this pub would have still been in use.

Now I know better.

I'm going to strip this pub down to something along the lines.

return Media.find({
     "metadata.type": "brandAsset"
   });

@prinzdezibel
Copy link
Contributor Author

prinzdezibel commented Jan 24, 2018

This publication may also be needed for some media documents under revision control.

Your statement would correlate with that code snippet, if I'm correct:

  if (RevisionApi.isRevisionControlEnabled()) {
    const revisionHandle = Revisions.find({
      "documentType": "image",
      "workflow.status": { $nin: [ "revision/published"] }
    }).observe({
      added: (revision) => {
        const media = Media.findOne(revision.documentId);
        if (media) {
          this.added("Media", media._id, media);
          this.added("Revisions", revision._id, revision);
        }
      },
      changed: (revision) => {
        const media = Media.findOne(revision.documentId);
        this.changed("Media", media._id, media);
        this.changed("Revisions", revision._id, revision);
      },
      removed: (revision) => {
        if (revision) {
          const media = Media.findOne(revision.documentId);
          if (media) {
            this.removed("Media", media._id, media);
            this.removed("Revisions", revision._id, revision);
          }
        }
      }
    });

I don't think it's necessary at all. For one all it does looks to me like an unnecessary roundtrip to the client, because it pushes revision and images when the revision is created and deletes it when the revision is published.

Also I'm wondering about the following two things:

a) The first push (the media object)
It pushes to an non-existent collection named "Media". But nowadays the collection is called "cfs.Media.filerecord" (I guess this happened when we changed to the implicit publishing process through products.js).

b) The second push (the Revision object)
Why should we bother to push the Revision to the user at all? Isn't this an admin-only thing?

NOTE In case you're asking where the 3.rd push is coming from: This results from my PR #3559.

Here is a gif for a better explanation (click on it to have it enlarged in a separate tab window):
unnecessaryrevisionrountrip

…for the brand

assets. But it's significantly less code.
@prinzdezibel
Copy link
Contributor Author

Changed as requested, @mikemurray. Also this PR does now incorporate the already approved & merged PR#3559.

@prinzdezibel prinzdezibel changed the title Remove unused publication. (perf, refactor) Remove unnecessary code in Media subscription. Jan 24, 2018
@@ -545,6 +545,27 @@ Meteor.publish("Products", function (productScrollLimit = 24, productFilters, so
const mediaProductIds = productCursor.fetch().map((p) => p._id);
const mediaCursor = findProductMedia(this, mediaProductIds);

const handle = productCursor.observe({
Copy link
Member

Choose a reason for hiding this comment

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

@prinzdezibel Isn't this equivalent to lines 546 and 571? All the media from the products and their variants should already be published unless I'm missing something here.

@brent-hoover
Copy link
Collaborator

Should probably be flagged as a breaking change since we are changing the name of a publication?

@prinzdezibel
Copy link
Contributor Author

prinzdezibel commented Feb 1, 2018

Should probably be flagged as a breaking change since we are changing the name of a publication?

Would probably only break, if somebody has overwritten the pub/sub, I guess.

@brent-hoover
Copy link
Collaborator

brent-hoover commented Feb 1, 2018

Or if they were subscribing to it in their own code. I would say changing the name of publication is probably one of the bigger API changes one could make.

@spencern spencern changed the base branch from master to release-1.8.0 February 2, 2018 16:52
@spencern spencern merged commit 3093407 into release-1.8.0 Feb 2, 2018
@spencern spencern deleted the fix-3557-prinzdezibel-remove-media-publication branch February 2, 2018 16:52
@spencern spencern mentioned this pull request Feb 5, 2018
@machikoyasuda
Copy link
Contributor

@prinzdezibel - Assigning you this doc ticket reactioncommerce/reaction-docs#490 to update https://docs.reactioncommerce.com/reaction-docs/master/image-handling to reflect this name change

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.

5 participants