<commit_before>// @flow

import type { GlobalAccountUserInfo } from 'lib/types/user-types';
import type { UserSearchRequest } from 'lib/types/search-types';

import { dbQuery, SQL } from '../database/database';

async function searchForUsers(
  query: UserSearchRequest,
): Promise<GlobalAccountUserInfo[]> {
  const sqlQuery = SQL`SELECT id, username FROM users `;
  const prefix = query.prefix;
  if (prefix) {
    sqlQuery.append(SQL`WHERE username LIKE ${prefix + '%'} `);
  }
  sqlQuery.append(SQL`LIMIT 20`);

  const [result] = await dbQuery(sqlQuery);

  const userInfos = [];
  for (let row of result) {
    userInfos.push({
      id: row.id.toString(),
      username: row.username,
    });
  }
  return userInfos;
}<commit_msg>Make user search case-insensitive<commit_after>// @flow

import type { GlobalAccountUserInfo } from 'lib/types/user-types';
import type { UserSearchRequest } from 'lib/types/search-types';

import { dbQuery, SQL } from '../database/database';

async function searchForUsers(
  query: UserSearchRequest,
): Promise<GlobalAccountUserInfo[]> {
  const sqlQuery = SQL`SELECT id, username FROM users `;
  const prefix = query.prefix;
  if (prefix) {
    sqlQuery.append(SQL`WHERE LOWER(username) LIKE LOWER(${prefix + '%'}) `);
  }
  sqlQuery.append(SQL`LIMIT 20`);

  const [result] = await dbQuery(sqlQuery);

  const userInfos = [];
  for (let row of result) {
    userInfos.push({
      id: row.id.toString(),
      username: row.username,
    });
  }
  return userInfos;
}
{'fraction_non_alphanumeric': 0.14105960264900663, 'fraction_numerical': 0.0026490066225165563, 'mean_word_length': 3.9218241042345277, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7558501', 'n_tokens_mistral': 487, 'n_tokens_neox': 477, 'n_words': 121}