Closed paulmolluzzo closed 10 years ago
i'm thinking i want to have a more robust rework of the subscriptions to handle this. something like
if not logged in > just send down jobs with updatedAt within 90 days
if directly accessing any job via url > always send down that job - need to add a 'job(id)' subscription/publication
if logged in > send all of my jobs
also, if viewing a job that is out of the 90 day bounds, show some alert 'this job is old, wont be shown in listing, but is still accessible via url, update the content of the job if you still want it to appear'
thinking we should just create a simple global variable 'DAYS_TILL_JOBS_EXPIRE' in like 'lib/environment.js' that we can use from client/server and adjust easily - 90 days seems good to start
@paulmolluzzo you interested in working this up? if not, i'll get it done within a week or so
I'm up for it!
Looking at the current subscriptions, I think it just requires doing a test for the Meteor.user()
in the route for the root path and using that to decide which parts of the jobs collection to return. The individual job via URL should work as is if the publication is set to return everything. I can use a common variable to make it easier to adjust in the future.
Hope to get to this today/tomorrow and I'll work on this branch and pull request instead of making a new one.
great! - here's some code snippets from other projects that should help some
sub out 'visual' for 'job' and this should make sense
main.js / router
this.route('visual', {
path: '/visuals/:_id',
onRun: function() {
Session.set('visualId',this.params._id);
},
data: function () {
return {
visual:Visuals.findOne({_id:this.params._id})
};
},
waitOn: function(){
return subscriptionHandles.visual;
}
});
subscriptions
subscriptionHandles = {
visuals:Meteor.subscribe("visuals")
};
Meteor.startup(function(){
Deps.autorun(function(){
if(Meteor.user()){
subscriptionHandles.user = Meteor.subscribe("my_user");
subscriptionHandles.my_visuals = Meteor.subscribe("my_visuals");
}else{
subscriptionHandles.user = undefined;
subscriptionHandles.my_visuals = undefined;
}
});
Deps.autorun(function(){
if(!Session.equals('visualId',undefined)){
if(subscriptionHandles.visual)
subscriptionHandles.visual.stop();
subscriptionHandles.visual = Meteor.subscribe("visual", Session.get('visualId'));
}else{
if(subscriptionHandles.visual)
subscriptionHandles.visual.stop();
subscriptionHandles.visual = undefined;
}
//this has a slight issue that you can subscribe to more than 1 object's full details, but that should be ok
});
});
publications
Meteor.publish("visuals", function(){
check(arguments, [Match.Any]);
return [
Visuals.find({})//would do date trimming here
];
});
Meteor.publish("my_visuals", function(){
check(arguments, [Match.Any]);
if(this.userId){
return [
Visuals.find({userId:this.userId})
];
}
this.ready();
});
Meteor.publish("visual", function(visualId){
check(arguments, [Match.Any]);
return [
Visuals.find({_id:visualId})
];
});
Thanks! This got me 90% of the way to the new subscriptions.
Here it is. I used the snippets you provided but had to integrate the new subscription names and the test for expired posts. The expiration is now controlled with a single number in lib/environment.js
.
If you find any bugs, feel free to let me know or clean them up as you like.
Thanks again for the snippets above, learned something new today.
thanks!
You bet! Glad this one worked out.
This is really basic. It only publishes Jobs that were created greater than 90 days ago. All subscriptions and permissions remain intact. Just keep in mind that even the Job post creator won't be able to see these posts. It'll kind of appear as if they were deleted.
If you want to change this to a different number of days, just change
90
to whatever # of days.A more robust action is the alter the subscription methodology based on your account settings, but the current way that's set up would mean restructuring all the subscriptions. (They're all just "on".)