Skip to content

Commit

Permalink
Continued work on generating views
Browse files Browse the repository at this point in the history
  • Loading branch information
kurbaniec committed Dec 16, 2023
1 parent 5cc1df1 commit a6f6dcd
Showing 1 changed file with 72 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,30 +78,92 @@ class BeePersistentViewCodegen(

private val debugInfo = mutableMapOf<String, MutableSet<String>>()

// private fun FileSpec.Builder.processEntity(
// entity: EntityInfo, viewCount: ViewCount
// ): String {
// val viewName = viewCount.viewName(entity, null)
//
// if (!debugInfo.containsKey(viewName)) {
// debugInfo[viewName] = mutableSetOf()
// }
//
// //logger.info("View $viewName")
// for (relation in entity.relations) {
//
// // logger.info(relation.toString())
// // logger.info("${relation.simpleName} X ${relation.qualifiedName}")
//
// val relationEntity = entitiesMap[relation.qualifiedName!!] ?: continue
// val relationView = processEntity(relationEntity, viewCount, entity)
// //logger.info(" View $viewName | ${relation.simpleName} => $relationView")
//
// if (relationView != null)
// debugInfo[viewName]?.add(relationView)
// }
//
// return viewName
// }

private fun FileSpec.Builder.processEntity(
entity: EntityInfo, viewCount: ViewCount
): String {
) {
val viewName = viewCount.viewName(entity, null)

if (!debugInfo.containsKey(viewName)) {
debugInfo[viewName] = mutableSetOf()
}

//logger.info("View $viewName")
val relationEntities = mutableListOf<ProcessE>()
for (relation in entity.relations) {
val relationEntity = entitiesMap[relation.qualifiedName!!] ?: continue
relationEntities.add(ProcessE(relationEntity, entity, viewName))
}
processEntities(relationEntities, viewCount, entity)
}

// logger.info(relation.toString())
// logger.info("${relation.simpleName} X ${relation.qualifiedName}")
data class ProcessE(
val entity: EntityInfo,
val parent: EntityInfo,
val parentViewName: String
)

val relationEntity = entitiesMap[relation.qualifiedName!!] ?: continue
val relationView = processEntity(relationEntity, viewCount.toMutableMap(), entity)
//logger.info(" View $viewName | ${relation.simpleName} => $relationView")
// TODO: Rewrite this more performant and better readable

if (relationView != null)
debugInfo[viewName]?.add(relationView)
private fun FileSpec.Builder.processEntities(
entities: List<ProcessE>, viewCount: ViewCount, root: EntityInfo
) {
val entities = entities.filterNot { (entity, parent) ->
viewCount.viewCountReached(entity)
}
if (entities.isEmpty()) return

return viewName

val uniqueEntities = entities.map { it.entity }.toSet()
for (entity in uniqueEntities) {
viewCount.incrementViewCount(entity)
}

for ((entity, parent, name) in entities) {
if (!debugInfo.containsKey(name)) {
debugInfo[name] = mutableSetOf()
}
val entityViewName = viewCount.viewName(entity, root)
debugInfo[name]?.add(entityViewName)
}

val newEntities = entities.map { (entity, parent) ->
val viewName = viewCount.viewName(entity, root)
val relationEntities = mutableListOf<ProcessE>()
for (relation in entity.relations) {
val relationEntity = entitiesMap[relation.qualifiedName!!] ?: continue
relationEntities.add(ProcessE(relationEntity, entity, viewName))
}
relationEntities
}.flatten()

// TODO: Clear duplicates...

processEntities(newEntities, viewCount, root)
}

private fun FileSpec.Builder.processEntity(
Expand Down

0 comments on commit a6f6dcd

Please sign in to comment.