<commit_before>'use strict';
const co = require('co');
const db = require('../schemes');
const Project = require('../models/project');
const addon = require('../../addons');

class ApiController {
    static getProjects (req, res) {
        Project.findByIncludedUsername(req.user.username)
            .then(projects => addon.callAddons('API', 'getProjects', {res, req, projects}))
            .then(({projects}) => res.status(200).json({message: 'OK', projects}))
            .catch(err => ApiController._serverError(res, err));
    }

    static getProject (req, res, next) {
        const username = req.user.username;
        co(function* () {
            let project = yield Project.findOne({where: {id: req.params.projectId}});
            if (!project) {
                return next();
            }
            if (!project.users.find(x => x.username === username)) {
                return res.status(403).json({message: 'you are not the project\'s member'});
            }
            const addonRes = yield addon.callAddons('API', 'getProject', {res, req, project});<commit_msg>improve performance of get project api<commit_after>'use strict';
const co = require('co');
const db = require('../schemes');
const Project = require('../models/project');
const addon = require('../../addons');

class ApiController {
    static getProjects (req, res) {
        Project.findByIncludedUsername(req.user.username)
            .then(projects => addon.callAddons('API', 'getProjects', {res, req, projects}))
            .then(({projects}) => res.status(200).json({message: 'OK', projects}))
            .catch(err => ApiController._serverError(res, err));
    }

    static getProject (req, res, next) {
        const username = req.user.username;
        co(function* () {
            let project = yield Project.findOneMedium({where: {id: req.params.projectId}});
            if (!project) {
                return next();
            }
            if (!project.users.find(x => x.username === username)) {
                return res.status(403).json({message: 'you are not the project\'s member'});
            }
            const addonRes = yield addon.callAddons('API', 'getProject', {res, req, project});
{'fraction_non_alphanumeric': 0.16463138851198553, 'fraction_numerical': 0.005427408412483039, 'mean_word_length': 2.567741935483871, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7183535', 'n_tokens_mistral': 628, 'n_tokens_neox': 614, 'n_words': 150}