Broken images after updating source&db in Vagrant


#1

I had sucessfully built up a virtual server through Vagrant and it worked well. However, when I updated its source and database in recent days, some of the images could’t load. Like this.

I checked in Chrome Inspector and found that some address had an 200 status code but responsed none. For example,
/file/db/thang.type/54693797a2b1f53ce79443e9/portrait.png

It seems that neither cleaning up my browser’s cache nor restarting the server worked correctly. Is there a solution to solve this problem?


#2

How are you updating the database?


#3

I combined backupMongo.sh and fillMongo.sh into a script and here’s the code.
mkdir -p /vagrant/temp
cd /vagrant/temp
rm -f dump.tar.gz
rm -rf dump
wget http://analytics.codecombat.com:8080/dump.tar.gz --no-cache
tar xzvf dump.tar.gz --no-same-owner
rm -fr backup
mkdir backup
cd backup
mongodump -db coco --collection users
mongodump -db coco --collection earnedachievements
cd …
mongorestore --drop
cd /vagrant/temp/backup
mongorestore


#4

Okay, so it’s weird that some Thangs have portraits and some don’t. Recently someone was saying that none of them had portraits and that coco.media.chunks was no longer included in the backup, which makes sense because thatw ould be huge, but then how come some of the items have portraits? More investigation is needed. Would you be willing to share that script in the wiki near the Vagrant stuff, and also to post a GitHub issue with this thread?


#5

Need I add the script into github? Or just copy into wiki?


#6

I’m guessing that coco.media.chunks isn’t being dropped/removed on any of the mongorestores, so some files that retain the same path will still be visible.


#7

Just copy into wiki, it’s short enough.

Maybe that’s it–usually I would do mongorestore --drop /vagrant/temp/backup, so maybe doing the mongorestore --drop the first time isn’t dropping, and then the mongorestore inside the backup dir is restoring and not dropping? How does that even work? Hmm.


#8

Well, I modified the script like this:

#foo
mongorestore --drop /vagrant/temp
mongorestore --drop /vagrant/temp/backup

However, the problem has’t been solved, maybe even worse.(The picture I had updated was lost too)


#9

I have a hacky script that should be able to regenerate most thang portraits—just run the dev server, open up the homepage, create an account, paste the code below into the console, clear cache (hold down refresh button on Chrome while DevTools are open), then navigate to http://localhost:3000/editor/thang to see if it worked:

// not working completely and eats up a lot of resources...

var CocoCollection = require('./collections/CocoCollection')
var ThangType = require('./models/ThangType')

var itemFetcher = new CocoCollection([], {
  url: '/db/thang.type',
  project: ['name', 'slug', 'original', 'raw', 'actions'],
  model: ThangType
})

itemFetcher.fetch({
  success: function (collection) {
    collection.forEach(function (thang) {
      thang.uploadGenericPortrait()
    })
  }
})

As for anything else, the closest idea I can come up with is to get all the file info from mongodb and POST /file a bunch of times, using the images on the CodeCombat site…


#10

OK so I come back again. The script by @trotod worked well, maybe. The thangs’ images has been fixed. However, there’s still a lot of problems needing to be solved.


As you can see, the background image is missing now. And, if users uploaded their photos, maybe they will lose later.


#11

I have drop the database of coco, but it still not work.