GithubHelp home page GithubHelp logo

Comments (5)

oleg-kiviljov avatar oleg-kiviljov commented on July 23, 2024

Hi @palkan, are there any ideas how this could be implemented?

from logidze.

palkan avatar palkan commented on July 23, 2024

I have one idea which could described as follows:

# add an option to specify whether we want a transaction or not 
# (this is mostly for backward compatibility)
def with_meta(data, transactional: true, &block)
  #  transactional_with_meta is the current implementation
  return MetaTransaction.wrap(data, &block) if transactional

  MetaNoTransaction.wrap(data, &block)
end

# the same as current MetaTransaction with the only one change
class Meta
  def perform
    raise ArgumentError, "Block must be given" unless block

    call_block_in_meta_context
  end

  def call_block_in_meta_context
    prev_meta = current_meta

    meta_stack.push(meta)

    pg_set_meta_param(current_meta)
    result = block.call

    result
  ensure
    # That's the only difference: we move reset to ensure to call it in case of exceptions
    pg_reset_meta_param(prev_meta)
    meta_stack.pop
  end
end

class MetaTransaction < BaseMeta
  def  call_block_in_meta_context
    ActiveRecord::Base.transaction { super }
  end
end

I hope, that should be enough)

from logidze.

oleg-kiviljov avatar oleg-kiviljov commented on July 23, 2024

Hi @palkan, I don't really get how the SET LOCAL is done without transaction based on your example.

from logidze.

palkan avatar palkan commented on July 23, 2024

Yeah, there is the point missing; when we're not within a transaction, we can only use SET (w/o LOCAL); and that's why we have to cleanup manually.

from logidze.

palkan avatar palkan commented on July 23, 2024

Closed by #143

from logidze.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.