@@ -12,7 +12,7 @@ module PlaceOS::Source
1212 Log = ::Log .for(self )
1313
1414 STATUS_CHANNEL_PATTERN = " status/#{ Model ::Module .table_name} -*"
15- MAX_CONTAINER_SIZE = 50_000
15+ MAX_CONTAINER_SIZE = 40_000
1616 BATCH_SIZE = 100
1717 PROCESSING_INTERVAL = 100 .milliseconds
1818 CONTAINER_WARNING_THRESHOLD = MAX_CONTAINER_SIZE * 0.8
@@ -66,11 +66,33 @@ module PlaceOS::Source
6666 redis.close
6767 end
6868
69+ def paginate_modules (& )
70+ batch_size = 64
71+ last_created_at = Time .unix(0 )
72+ last_id = " "
73+
74+ loop do
75+ modules = PlaceOS ::Model ::Module
76+ .where(" created_at > ? OR (created_at = ? AND id > ?)" , last_created_at, last_created_at, last_id)
77+ .order(created_at: :asc , id: :asc )
78+ .limit(batch_size)
79+ .to_a
80+
81+ # process
82+ break if modules.empty?
83+ yield modules
84+ break if modules.size < batch_size
85+
86+ last_created_at = modules.last.created_at
87+ last_id = modules.last.id
88+ end
89+ end
90+
6991 def update_values
7092 mods_mapped = 0 _u64
7193 status_updated = 0 _u64
7294 pattern = " initial_sync"
73- PlaceOS :: Model :: Module .order( id: :asc ).all.in_groups_of( 64 , reuse: true ) do |modules |
95+ paginate_modules do |modules |
7496 modules.each do |mod |
7597 next unless mod
7698 mods_mapped += 1 _u64
@@ -109,7 +131,7 @@ module PlaceOS::Source
109131 status_updated = 0 _u64
110132 pattern = " broker_resync"
111133
112- PlaceOS :: Model :: Module .order( id: :asc ).all.in_groups_of( 64 , reuse: true ) do |modules |
134+ paginate_modules do |modules |
113135 modules.each do |mod |
114136 next unless mod
115137 mods_mapped += 1 _u64
0 commit comments