<commit_before>import Ember from 'ember';
import ajax from 'ic-ajax';
import Version from 'cargo/models/version';
import Crate from 'cargo/models/crate';

export default Ember.Route.extend({
    title: Ember.computed.reads('controller.model.name'),

    setupController(controller, data) {
        if (data instanceof Crate) {
            data = {crate: data, version: null};
        } else if (data instanceof Version) {
            data = {crate: data.get('crate'), version: data.get('num')};
        }

        this._super(controller, data.crate);

        controller.set('showAllVersions', false);
        controller.set('fetchingDownloads', true);
        controller.set('fetchingFollowing', true);

        data.crate.get('keywords').then((keywords) => controller.set('keywords', keywords));

        if (this.session.get('currentUser')) {
            var url = '/api/v1/crates/' + data.crate.get('name') + '/following';

            ajax(url)
                .then((d) => controller.set('following', d.following))
                .finally(() => controller.set('fetchingFollowing', false));
        }

        // Try to find the requested version in the versions we fetch
        var max = data.crate.get('max_version');
        data.crate.get('versions').then((array) => {
            var hit = array.any((version) => {
                return data.version === version.get('num') ||
                           (data.version == null && version.get('num') === max);
            });

            if (!hit) {
                var msg = "Version `" + data.version + "` does not exist";
                this.controllerFor('application').set('flashError', msg);
                data.version = null;
            }
            controller.set('requestedVersion', data.version);

            array.forEach((version) => {
                if (data.version === version.get('num') ||
                    (data.version == null && version.get('num') === max)) {
                    controller.set('currentVersion', version);
                }
            });

        }).then(() => {
            if (controller.get('requestedVersion')) {
                return controller.get('currentVersion.version_downloads');
            } else {
                return controller.get('model.version_downloads');
            }
        }).then((downloads) => {
            var meta = downloads.get('meta');
            controller.set('fetchingDownloads', false);
            controller.send('renderChart', downloads, meta.extra_downloads);
        });
    }
});<commit_msg>routes/crate: Fix meta.extra_downloads handling<commit_after>import Ember from 'ember';
import ajax from 'ic-ajax';
import Version from 'cargo/models/version';
import Crate from 'cargo/models/crate';

export default Ember.Route.extend({
    title: Ember.computed.reads('controller.model.name'),

    setupController(controller, data) {
        if (data instanceof Crate) {
            data = {crate: data, version: null};
        } else if (data instanceof Version) {
            data = {crate: data.get('crate'), version: data.get('num')};
        }

        this._super(controller, data.crate);

        controller.set('showAllVersions', false);
        controller.set('fetchingDownloads', true);
        controller.set('fetchingFollowing', true);

        data.crate.get('keywords').then((keywords) => controller.set('keywords', keywords));

        if (this.session.get('currentUser')) {
            var url = '/api/v1/crates/' + data.crate.get('name') + '/following';

            ajax(url)
                .then((d) => controller.set('following', d.following))
                .finally(() => controller.set('fetchingFollowing', false));
        }

        // Try to find the requested version in the versions we fetch
        var max = data.crate.get('max_version');
        data.crate.get('versions').then((array) => {
            var hit = array.any((version) => {
                return data.version === version.get('num') ||
                           (data.version == null && version.get('num') === max);
            });

            if (!hit) {
                var msg = "Version `" + data.version + "` does not exist";
                this.controllerFor('application').set('flashError', msg);
                data.version = null;
            }
            controller.set('requestedVersion', data.version);

            array.forEach((version) => {
                if (data.version === version.get('num') ||
                    (data.version == null && version.get('num') === max)) {
                    controller.set('currentVersion', version);
                }
            });

        }).then(() => {
            return controller.get('model.version_downloads');
        }).then((downloads) => {
            var meta = downloads.get('meta');
            controller.set('fetchingDownloads', false);
            controller.send('renderChart', downloads, meta.extra_downloads);
        });
    }
});
{'fraction_non_alphanumeric': 0.1566532258064516, 'fraction_numerical': 0.0004032258064516129, 'mean_word_length': 2.0510455104551046, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1519381', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1285, 'n_words': 266}