in app/data/AtomListStore.scala [79:111]
override def getAtoms(search: Option[String], limit: Option[Int], shouldUseCreatedDateForSort: Boolean): MediaAtomList = {
// We must filter the entire list of atoms rather than use Dynamo limit to ensure stable iteration order.
// Without it, the front page will shuffle around when clicking the Load More button.
store.listAtoms match {
case Left(err) =>
AtomDataStoreError(err.msg)
case Right(atoms) =>
def sortField(atom: MediaAtom) =
if(shouldUseCreatedDateForSort)
atom.contentChangeDetails.created
else
atom.contentChangeDetails.lastModified
val mediaAtoms = atoms
.map(MediaAtom.fromThrift)
.toList
.sortBy(sortField(_).map(_.date.getMillis))
.reverse // newest atoms first
val filteredAtoms = search match {
case Some(str) => mediaAtoms.filter(_.title.contains(str))
case None => mediaAtoms
}
val limitedAtoms = limit match {
case Some(l) => filteredAtoms.take(l)
case None => filteredAtoms
}
MediaAtomList(filteredAtoms.size, limitedAtoms.map(fromAtom))
}
}