Class: Postnhost::Publishing::Revision

Inherits:
Object
  • Object
show all
Defined in:
app/services/postnhost/publishing/revision.rb

Overview

Serializes publication transitions on the singleton public site revision row.

The outermost hold owns the transaction, the row lock, and a single revision bump. Nested holds join it, so a bulk transition locks once and publishes as one public change instead of invalidating public caches per record.

Constant Summary collapse

STATE_KEY =
:postnhost_publishing_revision

Class Method Summary collapse

Class Method Details

.heldObject



26
27
28
# File 'app/services/postnhost/publishing/revision.rb', line 26

def self.held
  ActiveSupport::IsolatedExecutionState[STATE_KEY]
end

.holdObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/postnhost/publishing/revision.rb', line 11

def self.hold
  return yield if held

  ApplicationRecord.transaction do
    self.held = PublicSiteRevision.locked
    begin
      result = yield
      held.bump!
      result
    ensure
      self.held = nil
    end
  end
end