bdoyle0182 commented on a change in pull request #4986:
URL: https://github.com/apache/openwhisk/pull/4986#discussion_r506727492



##########
File path: 
common/scala/src/main/scala/org/apache/openwhisk/core/entity/WhiskAction.scala
##########
@@ -346,6 +358,74 @@ case class ExecutableWhiskActionMetaData(namespace: 
EntityPath,
 
 }
 
+case class WhiskActionVersion(id: String, namespace: EntityPath, name: 
EntityName, version: SemVer)
+
+object WhiskActionVersion {
+  val serdes = jsonFormat4(WhiskActionVersion.apply)
+}
+
+case class WhiskActionVersionList(namespace: EntityPath, name: EntityName, 
versions: Map[SemVer, String]) {
+  def matchedDocId(version: Option[SemVer]): Option[DocId] = {
+    version match {
+      case Some(ver) =>
+        versions.get(ver).map(DocId(_))
+      case None if versions.nonEmpty =>
+        Some(DocId(versions.maxBy(_._1.toString)._2))
+      case _ =>
+        None
+    }
+  }
+}
+
+object WhiskActionVersionList extends 
MultipleReadersSingleWriterCache[WhiskActionVersionList, DocInfo] {
+  lazy val viewName = WhiskQueries.entitiesView(collection = 
"action-versions").name
+
+  def cacheKey(action: FullyQualifiedEntityName): CacheKey = {
+    CacheKey(action.fullPath.asString)
+  }
+
+  def get(action: FullyQualifiedEntityName, datastore: EntityStore)(
+    implicit transId: TransactionId): Future[WhiskActionVersionList] = {
+    implicit val logger: Logging = datastore.logging
+    implicit val ec = datastore.executionContext
+
+    val key = List(action.fullPath.asString)
+    cacheLookup(
+      cacheKey(action),
+      datastore
+        .query(
+          viewName,
+          startKey = key,
+          endKey = key,
+          skip = 0,
+          limit = 0,
+          includeDocs = false,
+          descending = false,
+          reduce = false,
+          stale = StaleParameter.No)
+        .map { result =>
+          val values = result.map { row =>
+            row.fields("value").asJsObject()
+          }
+          val mappings = values
+            .map(WhiskActionVersion.serdes.read(_))
+            .map { actionVersion =>
+              (actionVersion.version, actionVersion.id)
+            }
+            .toMap
+          WhiskActionVersionList(action.namespace.toPath, action.name, 
mappings)
+        })
+  }
+
+  // delete cache
+  def deleteCache(action: FullyQualifiedEntityName)(implicit transId: 
TransactionId,

Review comment:
       Is there any possibility that this call fails which results in 
inconsistent data in the cache with what's in the db?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to