Tmp/cache needs to be manually cleared when developing plugins


(Atul Varma) #1

Hello! This is my first post, and I’m also completely new to rails, so apologies for any noobish mistakes I make here.

I was trying to get the simple Ubuntu OpenID plugin that @sam wrote working on my development discourse install, but while bundle exec rails s was clearly loading the code (I put some puts statements in there to make sure), there was no sign of its generated JavaScript assets being loaded in my browser.

After a few hours of tinkering and searching, I discovered comment #70 from @sohara mentioning that rm -rf tmp/cache fixed things for him, and this fixed things for me too!

However, I also noticed immediately after the comment that @sam mentioned that a bugfix had been applied which makes the need to manually clear tmp/cache obsolete. Upon reading the source for the bugfix, though, it appears that the code to automatically clear tmp/cache is only run during rake assets:precompile, which isn’t relevant to development. As far as I can tell, unless I am somehow doing development wrong, this means that tmp/cache still needs to be cleared when developing plugins (though not when deploying them).

Anyhow, I’m not sure if I’m doing development wrong, or if this is actually a bug, but I thought I’d mention it here.

P.S. - My original post contained more links that specifically referred to the comments I mentioned, but I was told after all this hard work that as a new user, I can only mention two links in a post, which was extremely frustrating. While I doubt I can convince anyone to drop such a “distrust-by-default” policy, it would be nice if the UI could inform users that they have too many links in real-time (rather than after they’ve peppered their post with helpful links and submitted the form), and it would also be nice if links to certain sites (such as other threads on the same discourse installation) could be exempted from the quota.


Exempt Links to other Topics/Posts from Link Limit?
(Ben T) #2

If you precompile assets, you are making a copy in time of all the javascript bits and writing it to a file. Every time a change is made (even minor) to the javascript you’ll have to precompile again.

For development purposes, you shouldn’t have to precompile assets. Just remove the assets that are precompiled from your install, and they should be generated as needed (and slowly.)


(Atul Varma) #3

So the thing is, as far as I know, I never did actually precompile assets… @sam also mentioned in the same thread that “assets precompile is meaningless in development”, so even if I did precompile them, doesn’t having precompiled assets override actual code render them not meaningless in development?

It seems like perhaps every time bundle exec rails s is called, either tmp/cache should automatically be deleted before starting the server, or the code should ignore the directory if it does exist. Or something else–even a note in the developer documentation–to ensure that new developers don’t have to spend hours debugging this kind of issue. (There is no mention of it in the “Discourse as your first Rails app” blog post, the vagrant developer guide, the advanced developer guide, the troubleshooting guide, or the Discourse readme.)


(Leo McArdle) #4

It’s been almost a year since this topic was created, but I just spent a good few hours scratching my head as to why my code plugging into plugin-outlets wasn’t working, before stumbling upon this.

Is this a bug? If it isn’t, and it’s expected behaviour, it really should be added to the vagrant documentation.


(Mittineague) #5

I’m still uncertain exactly when and when it isn’t necessary to rm -rf tmp

My take is
if changes involve yml files, yes, definitely.
otherwise, maybe not.

In other words, it depends on what the app is putting into the tmp file, not everything is cached.

Other times, if a plugin involves something that is handled by sidekiq, that needs to be run.


(Leo McArdle) #6

I found that, with your discourse-plugin-outlet-locations plugin, an item wouldn’t be added to the burger menu until I did a rm -rf tmp.

I’m developing my own plugin which tries to use the same site-map-links plugin outlet, and it too didn’t appear until I did a rm -rf tmp. I’m not sure if it’s required every time I change my template/view from now on, but I’m doing it anyway, because right now I’m more concerned with finishing this plugin, rather than working out the nuances of Discourse’s development mode caching. :stuck_out_tongue:


(Mittineague) #7

Hmmm, for me a hard page refresh did the trick.


(Leo McArdle) #8

Interesting, now I just need to refresh and Discourse will pick up any changes to my template and view. Could it be a rm -rf tmp is required when first adding to a plugin outlet, to get Discourse to recognise the addition?


(Mittineague) #9

Yes, I think that is because Discourse “registers” plugins. Once a plugin has been made known some changes to it take effect without needing an rm -rf tmp