<commit_before>package com.timgroup.mysqleventstore

import org.joda.time.DateTime


class InMemoryEventStore extends EventStore {
  var events = Vector[EffectiveEvent]()

  override def saveLiveEvent(newEvents: Seq[EventData], expectedVersion: Option[Long] = None): Unit = {
    val oldLast: Long = (0L +: (events.map(_.version))).max
    val newLast: Long = oldLast + newEvents.length
    events = events ++ newEvents.zipWithIndex.map {
      case (evt, index) =>
        EffectiveEvent(new DateTime(), evt, oldLast + 1 + index, newLast)
    }
  }

  override def saveBackfillEvent(newEvents: Seq[BackfillEvent], expectedVersion: Option[Long] = None): Unit = {
    val last: Long = (events.map(_.version) ++ newEvents.map(_.version)).max
    events = events ++ newEvents.zipWithIndex.map {
      case (evt, index) => EffectiveEvent(new DateTime(), evt.eventData, evt.version, last)
    }
  }

  override def fromAll(version: Long, batchSize: Option[Int] = None): EventStream = {
    val last = events.lastOption.map(_.version)

    val fetched = events.dropWhile(_.version <= version).take(batchSize.getOrElse(Int.MaxValue))

    EventStream(fetched.dropWhile(_.version <= version).toIterator.map(_.copy(lastVersion = last.get)))
  }
}
<commit_msg>Revert "tdenley/mstoy: fix exception when saving to previously empty in-memory event store"<commit_after>package com.timgroup.mysqleventstore

import org.joda.time.DateTime


class InMemoryEventStore extends EventStore {
  var events = Vector[EffectiveEvent]()

  override def saveLiveEvent(newEvents: Seq[EventData], expectedVersion: Option[Long] = None): Unit = {
    val oldLast: Long = events.map(_.version).max
    val newLast: Long = oldLast + newEvents.length
    events = events ++ newEvents.zipWithIndex.map {
      case (evt, index) =>
        EffectiveEvent(new DateTime(), evt, oldLast + 1 + index, newLast)
    }
  }

  override def saveBackfillEvent(newEvents: Seq[BackfillEvent], expectedVersion: Option[Long] = None): Unit = {
    val last: Long = (events.map(_.version) ++ newEvents.map(_.version)).max
    events = events ++ newEvents.zipWithIndex.map {
      case (evt, index) => EffectiveEvent(new DateTime(), evt.eventData, evt.version, last)
    }
  }

  override def fromAll(version: Long, batchSize: Option[Int] = None): EventStream = {
    val last = events.lastOption.map(_.version)

    val fetched = events.dropWhile(_.version <= version).take(batchSize.getOrElse(Int.MaxValue))

    EventStream(fetched.dropWhile(_.version <= version).toIterator.map(_.copy(lastVersion = last.get)))
  }
}

{'fraction_non_alphanumeric': 0.12889408099688474, 'fraction_numerical': 0.0011682242990654205, 'mean_word_length': 4.264344262295082, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1565860', 'n_tokens_mistral': 804, 'n_tokens_neox': 792, 'n_words': 178}