<commit_before>import { find, get, isNull, isUndefined, merge, pick } from 'lodash'
import { filter, pickBy } from 'lodash/fp'
import { normalizeMemberships, normalizePost, uniqize } from '../../lib/util/normalize'
import { fetchAndPresentFollowed } from '../services/TagPresenter'

const relationsForSelf = [
  'memberships',
  {'memberships.community': qb => qb.column('id', 'name', 'slug', 'avatar_url')},
  'tags',
  'linkedAccounts'
]

const recentTaggedPost = (userId, tag, viewingUserId) => {
  const opts = {withComments: true, withVotes: true}
  return Post.query(q => {
    q.join('posts_tags', 'posts.id', 'posts_tags.post_id')
    q.join('tags', 'tags.id', 'posts_tags.tag_id')
    q.where({
      'tags.name': tag,
      user_id: userId,
      parent_post_id: null
    })
    q.orderBy('id', 'desc')
    q.limit(1)
  })
  .fetch({withRelated: PostPresenter.relations(viewingUserId, opts)})
  .then(post => post && PostPresenter.present(post, viewingUserId, opts))
}

const extraAttributes = (user, viewingUserId, forSelf) =>
  Promise.props({
    post_count: Post.countForUser(user),
    event_count: Post.countForUser(user, 'event'),
    grouped_post_count: Post.groupedCountForUser(user),<commit_msg>check viewing user's memberships when fetching recent request & offer for a user<commit_after>import { find, get, isNull, isUndefined, merge, pick } from 'lodash'
import { filter, pickBy } from 'lodash/fp'
import { normalizeMemberships, normalizePost, uniqize } from '../../lib/util/normalize'
import { fetchAndPresentFollowed } from '../services/TagPresenter'

const relationsForSelf = [
  'memberships',
  {'memberships.community': qb => qb.column('id', 'name', 'slug', 'avatar_url')},
  'tags',
  'linkedAccounts'
]

const recentTaggedPost = (userId, tag, viewingUserId) => {
  const opts = {withComments: true, withVotes: true}
  return Post.query(q => {
    q.join('posts_tags', 'posts.id', 'posts_tags.post_id')
    q.join('tags', 'tags.id', 'posts_tags.tag_id')
    q.join('communities_posts', 'communities_posts.post_id', 'posts.id')
    q.where({
      'tags.name': tag,
      user_id: userId,
      parent_post_id: null
    })
    q.where('communities_posts.community_id', 'in',
      Membership.activeCommunityIds(viewingUserId))
    q.orderBy('id', 'desc')
    q.limit(1)
  })
  .fetch({withRelated: PostPresenter.relations(viewingUserId, opts)})
  .then(post => post && PostPresenter.present(post, viewingUserId, opts))
}

const extraAttributes = (user, viewingUserId, forSelf) =>
  Promise.props({
    post_count: Post.countForUser(user),
    event_count: Post.countForUser(user, 'event'),
    grouped_post_count: Post.groupedCountForUser(user),
{'fraction_non_alphanumeric': 0.15706806282722513, 'fraction_numerical': 0.0007479431563201197, 'mean_word_length': 4.5845511482254695, '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': '643938', 'n_tokens_mistral': 918, 'n_tokens_neox': 909, 'n_words': 186}