Skip to content

Instantly share code, notes, and snippets.

@sscarduzio
Created January 27, 2016 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sscarduzio/8043b7c48eb737939498 to your computer and use it in GitHub Desktop.
Save sscarduzio/8043b7c48eb737939498 to your computer and use it in GitHub Desktop.
Refactor ensime-server indexer (excerpt)
// Proposed code
override def receive: Receive = {
// ... snip ...
for {
indexed <- Future.sequence(batch.map {
case (_, f) =>
if (!f.exists()) Future.successful(f -> Nil)
else searchService.extractSymbolsFromClassOrJar(f).map(f ->)
})
.recoverWith { case t: Throwable => log.error(s"failed to index batch of ${batch.size} files", t); Future.failed(t)}
_ <- searchService.delete(indexed.map(_._1)(collection.breakOut))
.recoverWith { case t: Throwable => log.error(s"failed to remove stale entries in ${batch.size} files", t); Future.failed(t) }
toPersist = indexed.filter(kv => !kv._2.isEmpty)
_ <- Future.sequence(
toPersist.map { kv =>
val file = kv._1
val syms = kv._2
searchService.persist(FileCheck(file), syms, commitIndex = true)
.recoverWith { case t: Throwable => log.error(s"failed to persist entries in $file", t); Future.failed(t) }
}
)
} yield ()
}
// Original source
override def receive: Receive = {
// ... snip ...
Future.sequence(batch.map {
case (_, f) =>
if (!f.exists()) Future.successful(f -> Nil)
else searchService.extractSymbolsFromClassOrJar(f).map(f -> )
}).onComplete {
case Failure(t) =>
log.error(s"failed to index batch of ${batch.size} files", t)
case Success(indexed) =>
searchService.delete(indexed.map(_._1)(collection.breakOut)).onComplete {
case Failure(t) => log.error(s"failed to remove stale entries in ${batch.size} files", t)
case Success(_) => indexed.collect {
case (file, syms) if syms.isEmpty =>
case (file, syms) =>
searchService.persist(FileCheck(file), syms, commitIndex = true).onComplete {
case Failure(t) => log.error(s"failed to persist entries in $file", t)
case Success(_) =>
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment