Revert "Fire EntityChange events immediately"

This reverts commit d2114006
This commit is contained in:
Tapac
2020-01-13 13:26:53 +03:00
parent d21140063d
commit aba172ae76
2 changed files with 13 additions and 6 deletions

View File

@@ -38,16 +38,22 @@ object EntityHook {
}
fun Transaction.registerChange(entityClass: EntityClass<*, Entity<*>>, entityId: EntityID<*>, changeType: EntityChangeType) {
val event = EntityChange(entityClass, entityId, changeType, id)
if (entityEvents.lastOrNull() != event) {
entityEvents.add(event)
entitySubscribers.forEach {
it(event)
EntityChange(entityClass, entityId, changeType, id).let {
if (entityEvents.lastOrNull() != it) {
entityEvents.add(it)
}
}
}
fun Transaction.alertSubscribers() {
entityEvents.forEach { e ->
entitySubscribers.forEach {
it(e)
}
}
entityEvents.clear()
}
fun Transaction.registeredChanges() = entityEvents.toList()
fun <T> withHook(action: (EntityChange) -> Unit, body: ()->T): T {

View File

@@ -38,6 +38,7 @@ class EntityLifecycleInterceptor : GlobalStatementInterceptor {
override fun beforeCommit(transaction: Transaction) {
val created = transaction.flushCache()
transaction.alertSubscribers()
val createdByHooks = transaction.flushCache()
EntityCache.invalidateGlobalCaches(created + createdByHooks)
}