<commit_before>var sortColumns = {
  'fulfilled-last': 'fulfilled_at',
  'top': 'post.num_votes',
  'recent': 'post.updated_at',
  'suggested': 'suggested'
}

var findPosts = function (req, res, opts) {
  var params = _.merge(
    _.pick(req.allParams(), ['sort', 'limit', 'offset', 'type', 'start_time', 'end_time']),
    _.pick(opts, 'sort')
  )

  Promise.props({
    communities: opts.communities,
    project: opts.project,
    users: opts.users,
    type: params.type,
    limit: params.limit,
    offset: params.offset,
    start_time: params.start_time,
    end_time: params.end_time,
    visibility: opts.visibility,
    sort: sortColumns[params.sort || 'recent'],
    forUser: req.session.userId
  })
  .then(args => Search.forPosts(args).fetchAll({
    withRelated: PostPresenter.relations(req.session.userId, opts.relationsOpts)
  }))
  .then(PostPresenter.mapPresentWithTotal)
  .then(res.ok, res.serverError)
}

var newPostAttrs = function (userId, params) {
  return _.merge(Post.newPostAttrs(), {
    name: RichText.sanitize(params.name),
    description: RichText.sanitize(params.description),
    type: params.type,
    user_id: userId
  })
}

var createImage = function (postId, url, trx) {
  return Media.create({
    post_id: postId,
    url: url,
    type: 'image',
    transacting: trx
  })
}

var createDoc = function (postId, doc, trx) {
  return Media.create({
    post_id: postId,
    url: doc.url,
    type: 'gdoc',
    name: doc.name
  })
}

var afterSavingPost = function (post, opts) {
  var userId = post.get('user_id')
  var mentioned = RichText.getUserMentions(post.get('description'))
  var followerIds = _.uniq(mentioned.concat(userId))

  return Promise.all(_.flatten([
    // Attach post to communities
    opts.communities.map(id => new Community({id: id}).posts().attach(post.id, _.pick(opts, 'transacting'))),

    // Add mentioned users and creator as followers
    post.addFollowers(followerIds, userId, _.pick(opts, 'transacting')),

    // create activity and send notification to all mentioned users except the creator
    Promise.map(_.without(mentioned, userId), mentionedUserId => Post.notifyAboutMention(post, mentionedUserId, _.pick(opts, 'transacting'))),

    // Add image, if any
    (opts.imageUrl && createImage(post.id, opts.imageUrl, opts.transacting)),

    (opts.docs && Promise.map(opts.docs, doc => createDoc(post.id, doc, opts.transacting)))
  ])).then(() => mentioned)
}

module.exports = {<commit_msg>fix saving gdocs for a new post<commit_after>var sortColumns = {
  'fulfilled-last': 'fulfilled_at',
  'top': 'post.num_votes',
  'recent': 'post.updated_at',
  'suggested': 'suggested'
}

var findPosts = function (req, res, opts) {
  var params = _.merge(
    _.pick(req.allParams(), ['sort', 'limit', 'offset', 'type', 'start_time', 'end_time']),
    _.pick(opts, 'sort')
  )

  Promise.props({
    communities: opts.communities,
    project: opts.project,
    users: opts.users,
    type: params.type,
    limit: params.limit,
    offset: params.offset,
    start_time: params.start_time,
    end_time: params.end_time,
    visibility: opts.visibility,
    sort: sortColumns[params.sort || 'recent'],
    forUser: req.session.userId
  })
  .then(args => Search.forPosts(args).fetchAll({
    withRelated: PostPresenter.relations(req.session.userId, opts.relationsOpts)
  }))
  .then(PostPresenter.mapPresentWithTotal)
  .then(res.ok, res.serverError)
}

var newPostAttrs = function (userId, params) {
  return _.merge(Post.newPostAttrs(), {
    name: RichText.sanitize(params.name),
    description: RichText.sanitize(params.description),
    type: params.type,
    user_id: userId
  })
}

var createImage = function (postId, url, trx) {
  return Media.create({
    post_id: postId,
    url: url,
    type: 'image',
    transacting: trx
  })
}

var createDoc = function (postId, doc, trx) {
  return Media.create({
    post_id: postId,
    url: doc.url,
    type: 'gdoc',
    name: doc.name,
    transacting: trx
  })
}

var afterSavingPost = function (post, opts) {
  var userId = post.get('user_id')
  var mentioned = RichText.getUserMentions(post.get('description'))
  var followerIds = _.uniq(mentioned.concat(userId))

  return Promise.all(_.flatten([
    // Attach post to communities
    opts.communities.map(id => new Community({id: id}).posts().attach(post.id, _.pick(opts, 'transacting'))),

    // Add mentioned users and creator as followers
    post.addFollowers(followerIds, userId, _.pick(opts, 'transacting')),

    // create activity and send notification to all mentioned users except the creator
    Promise.map(_.without(mentioned, userId), mentionedUserId => Post.notifyAboutMention(post, mentionedUserId, _.pick(opts, 'transacting'))),

    // Add image, if any
    (opts.imageUrl && createImage(post.id, opts.imageUrl, opts.transacting)),

    (opts.docs && Promise.map(opts.docs, doc => createDoc(post.id, doc, opts.transacting)))
  ])).then(() => mentioned)
}

module.exports = {
{'fraction_non_alphanumeric': 0.1500402252614642, 'fraction_numerical': 0.0, 'mean_word_length': 3.8995073891625616, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '7299014', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1649, 'n_words': 368}