Optimising resetting of demo data
In one of the apps we support we need to have "realistic demonstration data" for our salespeople to use in demoing and selling.
We currently have a rake task that resets this demo data once a day, however it's really quite inefficient and slow (it takes about 5 - 10minutes to run through)
There are definitely ways that I could optimise the code which generates the demo data (which I'm planning to do) but开发者_如何学Python I'm thinking that there is probably a better way to do this altogether...
What I'm hoping to do is grab the output of the reset (i.e. grab the raw SQL). I'm hoping with this I can just make a scheduled task which resets the demo data directly to the DB everyday instead of having to load the whole Rails environment and execute a bunch of ruby methods.
This way I can only run the slow task when the nature of the demo data changes (which is quite rare) in order to update my SQL.
Is this the best approach? How can I grab the SQL in a nice format?
It seems to be a good solution! if you have no asset at all simple make a dump a.e. in mysql
mysqldump -uUSER -pPASSWORD [other params] DATABASE > yourdumpfile.sql
and to restore
mysql -uUSER -pPASS DATABASE < yourdumpfile.sql
here a usefull rake task that you could use. bye
I can't tell by your question but is your rake task using some rails specific ways of creating the data? For example, a gem like faker? I'll answer assuming that you are.
If you're thinking of saving and re-running the sql that faker (or something similar) creates then I'd say that's a bad idea. You said the data rarely changes so on those rare occasions just use your rails environment.
But once you have the data you need go with what @andrea suggested and dump the data and restore it.
精彩评论