Fire EntityChange events immediately

This commit is contained in:
Tapac
2020-01-11 11:14:51 +03:00
parent 179142f816
commit d21140063d
2 changed files with 4 additions and 11 deletions

View File

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

View File

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