<commit_before>import { PullRequestDatabase, IPullRequest } from '../databases'
import { GitHubRepository } from '../../models/github-repository'
import { Account } from '../../models/account'
import { API, IAPIPullRequest } from '../api'
import { fatalError, forceUnwrap } from '../fatal-error'
import { RepositoriesStore } from './repositories-store'
import { PullRequest, PullRequestRef } from '../../models/pull-request'
import { TypedBaseStore } from './base-store'
import { Repository } from '../../models/repository'
import { getRemotes, removeRemote } from '../git'
import { ForkedRemotePrefix } from '../../models/remote'

const Decrement = (n: number) => n - 1
const Increment = (n: number) => n + 1

/** The store for GitHub Pull Requests. */
export class PullRequestStore extends TypedBaseStore<GitHubRepository> {
  private readonly pullRequestDatabase: PullRequestDatabase
  private readonly repositoryStore: RepositoriesStore
  private readonly activeFetchCountPerRepository = new Map<number, number>()

  public constructor(
    db: PullRequestDatabase,
    repositoriesStore: RepositoriesStore
  ) {
    super()

    this.pullRequestDatabase = db
    this.repositoryStore = repositoriesStore<commit_msg>getLatestUpdatedAt, same as for issues<commit_after>import { PullRequestDatabase, IPullRequest } from '../databases'
import { GitHubRepository } from '../../models/github-repository'
import { Account } from '../../models/account'
import { API, IAPIPullRequest } from '../api'
import { fatalError, forceUnwrap } from '../fatal-error'
import { RepositoriesStore } from './repositories-store'
import { PullRequest, PullRequestRef } from '../../models/pull-request'
import { TypedBaseStore } from './base-store'
import { Repository } from '../../models/repository'
import { getRemotes, removeRemote } from '../git'
import { ForkedRemotePrefix } from '../../models/remote'

const Decrement = (n: number) => n - 1
const Increment = (n: number) => n + 1

/** The store for GitHub Pull Requests. */
export class PullRequestStore extends TypedBaseStore<GitHubRepository> {
  private readonly pullRequestDatabase: PullRequestDatabase
  private readonly repositoryStore: RepositoriesStore
  private readonly activeFetchCountPerRepository = new Map<number, number>()

  public constructor(
    db: PullRequestDatabase,
    repositoriesStore: RepositoriesStore
  ) {
    super()

    this.pullRequestDatabase = db
    this.repositoryStore = repositoriesStore
  }

  /**
   * Get the highest value of the 'updatedAt' field for PRs in a given
   * repository. This value is used to request delta updates from the API
   * using the 'since' parameter.
   */
  private async getLatestUpdatedAt(
    repository: GitHubRepository
  ): Promise<Date | null> {
    const gitHubRepositoryID = repository.dbID
    if (!gitHubRepositoryID) {
      return fatalError(
        "Cannot get issues for a repository that hasn't been inserted into the database!"
      )
    }

    const latestUpdatedPullRequest = await this.pullRequestDatabase.pullRequests
      .where('[base.repoId+updatedAt]')
      .between([gitHubRepositoryID], [gitHubRepositoryID + 1], true, false)
      .last()

    if (!latestUpdatedPullRequest || !latestUpdatedPullRequest.updatedAt) {
      return null
    }

    const lastUpdatedAt = new Date(latestUpdatedPullRequest.updatedAt)

    return !isNaN(lastUpdatedAt.getTime()) ? lastUpdatedAt : null
{'fraction_non_alphanumeric': 0.11296458882060287, 'fraction_numerical': 0.0014632718759145448, 'mean_word_length': 4.019089574155654, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, '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': '4613013', 'n_tokens_mistral': 930, 'n_tokens_neox': 902, 'n_words': 278}