Skip to content

Commit

Permalink
Merge pull request #3558 from reactioncommerce/fix-3557-prinzdezibel-…
Browse files Browse the repository at this point in the history
…remove-media-publication

(perf, refactor) Remove unnecessary code in Media subscription.
  • Loading branch information
spencern authored Feb 2, 2018
2 parents 22a2a50 + 5f6af43 commit 3093407
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 73 deletions.
2 changes: 1 addition & 1 deletion client/modules/core/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Subscriptions.Tags = Subscriptions.Manager.subscribe("Tags");

Subscriptions.Groups = Subscriptions.Manager.subscribe("Groups");

Subscriptions.Media = Subscriptions.Manager.subscribe("Media");
Subscriptions.BrandAssets = Subscriptions.Manager.subscribe("BrandAssets");

/**
* Subscriptions that need to reload on new sessions
Expand Down
76 changes: 4 additions & 72 deletions server/publications/collections/media.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,11 @@
import { Meteor } from "meteor/meteor";
import { check, Match } from "meteor/check";
import { Media, Revisions } from "/lib/collections";
import { Reaction } from "/server/api";
import { RevisionApi } from "/imports/plugins/core/revisions/lib/api/revisions";
import { Media } from "/lib/collections";


/**
* CollectionFS - Image/Video Publication
* @params {Array} shops - array of current shop object
*/
Meteor.publish("Media", function (shops) {
check(shops, Match.Optional(Array));
let selector;
const shopId = Reaction.getShopId();
if (!shopId) {
return this.ready();
}
if (shopId) {
selector = {
"metadata.shopId": shopId
};
}
if (shops) {
selector = {
"metadata.shopId": {
$in: shops
}
};
}

// Product editors can see both published and unpublished images
if (!Reaction.hasPermission(["createProduct"], this.userId)) {
selector["metadata.workflow"] = {
$in: [null, "published"]
};
} else {
// but no one gets to see archived images
selector["metadata.workflow"] = {
$nin: ["archived"]
};
}

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);
}
}
}
});

this.onStop(() => {
revisionHandle.stop();
});
}

* CollectionFS - Brand asset publication
*/
Meteor.publish("BrandAssets", function () {
return Media.find({
"metadata.type": "brandAsset"
});
Expand Down

0 comments on commit 3093407

Please sign in to comment.