superscriptjs / superscript

A dialogue engine for creating chat bots
http://superscriptjs.com
MIT License
1.65k stars 209 forks source link

Users get deleted after server restart #366

Open antonispoulakis opened 7 years ago

antonispoulakis commented 7 years ago

Users get deleted every time server gets restarted.

Expected Behavior

The users should be saved in the database and be loaded in the bot instance when it is started.

Current Behavior

When the bot is instantiated from the server, all the models are removed from the database and get imported again at a later stage. The User model is not being imported again apparently, because the ss_users collection is empty

Possible Solution

I noticed that if we remove User from the following array, the users remain in the collection in mongo with no obvious side effect.

The other items in this array are getting imported from the data.json file, but users are not being imported from anywhere, so they should not be removed, they should be persistent

In lib/bot/db/import.js, line 184:

...
  // Remove everything before we start importing
  _async2.default.each([Gambit, Reply, Topic, User], (model, nextModel) => {
    model.remove({}, err => nextModel());
  }, err => 
...

to this:

...
  // Remove everything before we start importing
  _async2.default.each([Gambit, Reply, Topic], (model, nextModel) => {
    model.remove({}, err => nextModel());
  }, err => 
...

Your Environment