mirror of
https://github.com/jlengrand/Exposed.git
synced 2026-03-10 08:11:20 +00:00
Revert "Fire EntityChange events immediately"
This reverts commit d2114006
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user