• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

umbrellio / umbrellio-sequel-plugins / 27339044606

11 Jun 2026 09:59AM UTC coverage: 97.373%. First build
27339044606

push

github

KirIgor
fix lint

24 of 27 new or added lines in 2 files covered. (88.89%)

556 of 571 relevant lines covered (97.37%)

34.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.25
/lib/sequel/plugins/concurrent_thread_pool_eager_loading.rb
1
# frozen_string_literal: true
2

3
module Sequel
4✔
4
  module Plugins
4✔
5
    # Concurrent eager loading using concurrent_thread_pool extension.
6
    # Adapted from Sequel's built-in concurrent_eager_loading plugin but uses
7
    # our concurrent_thread_pool extension instead of async_thread_pool.
8
    #
9
    # Usage:
10
    #
11
    #   DB.extension(:concurrent_thread_pool)
12
    #   Album.plugin :concurrent_thread_pool_eager_loading
13
    #   Album.eager_load_concurrently.eager(:artist, :genre, :tracks).all
14
    #
15
    #   # Always concurrent by default:
16
    #   Album.plugin :concurrent_thread_pool_eager_loading, always: true
17
    module ConcurrentThreadPoolEagerLoading
4✔
18
      def self.configure(mod, opts = OPTS)
4✔
19
        if opts.key?(:always)
56✔
20
          mod.instance_variable_set(:@always_eager_load_concurrently, opts[:always])
16✔
21
        end
22
      end
23

24
      module ClassMethods
4✔
25
        Plugins.inherited_instance_variables(self, :@always_eager_load_concurrently => nil)
4✔
26
        Plugins.def_dataset_methods(self, [:eager_load_concurrently, :eager_load_serially])
4✔
27

28
        def always_eager_load_concurrently?
4✔
29
          @always_eager_load_concurrently
12✔
30
        end
31
      end
32

33
      module DatasetMethods
4✔
34
        def eager_load_concurrently
4✔
35
          cached_dataset(:_eager_load_concurrently) do
20✔
36
            clone(eager_load_concurrently: true)
20✔
37
          end
38
        end
39

40
        def eager_load_serially
4✔
41
          cached_dataset(:_eager_load_serially) do
8✔
42
            clone(eager_load_concurrently: false)
8✔
43
          end
44
        end
45

46
        private
4✔
47

48
        def eager_load_concurrently?
4✔
49
          v = @opts[:eager_load_concurrently]
24✔
50
          v.nil? ? model.always_eager_load_concurrently? : v
24✔
51
        end
52

53
        def perform_eager_loads(eager_load_data)
4✔
54
          return super if !eager_load_concurrently? || eager_load_data.length < 2
24✔
55

56
          mutex = Mutex.new
×
NEW
57
          eager_load_data.each_value do |elo|
×
NEW
58
            elo[:mutex] = mutex
×
59
          end
60

61
          super.each do |v|
×
NEW
62
            if v.is_a?(Sequel::Database::ConcurrentThreadPool::BaseProxy)
×
63
              v.__value
×
64
            end
65
          end
66
        end
67

68
        def perform_eager_load(loader, elo)
4✔
69
          elo[:mutex] ? db.send(:async_run) { super } : super
24✔
70
        end
71
      end
72
    end
73
  end
74
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc