snowflaked 0.1.3-arm-linux → 0.2.0-arm-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38fc2352d02dd80016be6d3998758807ce1a4ccb38d1d023cc6162b08cbf9d1a
4
- data.tar.gz: 0ae9a58b29de3bef02ce745d4e8fe6d53f7e4320403d392316b8ea87a357f675
3
+ metadata.gz: f29453adb3b5beb29e002cd5471ffa8dd00c11ba2bf3ae1160045fe4234445d8
4
+ data.tar.gz: eab2733f6bbde075997970e72ed644580ddd208dc9a00d2f522489c98a048ab0
5
5
  SHA512:
6
- metadata.gz: 9861a1d5b31bb0089bdbd7099bfa22e18d37f6079e0e7e03394686ef874575547d4bfc214c2baa02001e18afa1356667a23c9e2efb64dee06e3778aaa14f7a8f
7
- data.tar.gz: b588edc1d663adf0e6a59c6ef6c5c7b0ccff64450838d95b4d17ae27372f4cd621c08e70811bb437312c56cfc789e2d5fda21fb19c8e99686e3ad04988767da3
6
+ metadata.gz: 2cbcc046f261d2802a8b5a4c980d5be51a12f2ae8acb232c40365d20b073645ceb5801660380b6e66ac4d7e6ad0a0fdf58e26b0e631478db8133504debcb6305
7
+ data.tar.gz: f2dc3cdfe2063ac7b0a5add70488c79dce1b8a33f611bbc6b8e9f9ed0aa016cf1a208ccb5b0d9a276c4c8fe67eeb9a095dab8761fbca3ee1dba4318e64d2c54b
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Downloads](https://img.shields.io/gem/dt/snowflaked.svg)](https://rubygems.org/gems/snowflaked)
6
6
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.txt)
7
7
 
8
- A high-performance, thread-safe Snowflake ID generator for Ruby, powered by Rust.
8
+ A database-agnostic, high-performance, thread-safe Snowflake ID generator for Ruby, powered by Rust.
9
9
 
10
10
  Snowflake IDs are 64-bit unique identifiers that encode a timestamp, machine ID, and sequence number. They're time-sortable (IDs created later are always larger), making them ideal for distributed systems where you need unique IDs without coordination between machines. Unlike UUIDs, Snowflake IDs are smaller, sortable, and index-friendly for databases.
11
11
 
@@ -143,6 +143,12 @@ Snowflaked.machine_id(id)
143
143
  # => 42
144
144
  ```
145
145
 
146
+ ## Benchmarks
147
+
148
+ See [BENCHMARKS.md](benchmarks/README.md) for more details.
149
+
150
+ tl;dr: Snowflake IDs have a negligible performance impact compared to database-backed IDs.
151
+
146
152
  ## Requirements
147
153
 
148
154
  - Ruby >= 3.2
Binary file
Binary file
Binary file
Binary file
@@ -14,25 +14,27 @@ module Snowflaked
14
14
  attrs = attributes.map(&:to_sym)
15
15
  attrs |= [:id] if id
16
16
  self._snowflake_attributes = attrs
17
+ @_snowflake_attributes_with_columns = nil
17
18
  end
18
19
 
19
20
  def _snowflake_columns_from_comments
20
21
  return @_snowflake_columns_from_comments if defined?(@_snowflake_columns_from_comments)
21
22
 
22
- @_snowflake_columns_from_comments = if table_exists?
23
- columns.filter_map { |col| col.name.to_sym if col.comment == Snowflaked::SchemaDefinitions::COMMENT }
24
- else
25
- []
26
- end
23
+ @_snowflake_columns_from_comments = table_exists? ? columns.filter_map { |col| col.name.to_sym if col.comment == Snowflaked::SchemaDefinitions::COMMENT } : []
24
+ end
25
+
26
+ def _snowflake_attributes_with_columns
27
+ @_snowflake_attributes_with_columns ||= (_snowflake_attributes | _snowflake_columns_from_comments)
27
28
  end
28
29
  end
29
30
 
30
31
  private
31
32
 
32
33
  def _generate_snowflake_ids
33
- attributes_to_generate = self.class._snowflake_attributes | self.class._snowflake_columns_from_comments
34
+ attributes = self.class._snowflake_attributes_with_columns
35
+ return if attributes.empty?
34
36
 
35
- attributes_to_generate.each do |attribute|
37
+ attributes.each do |attribute|
36
38
  next if self[attribute].present?
37
39
 
38
40
  self[attribute] = Snowflaked.id
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snowflaked
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/snowflaked.rb CHANGED
@@ -29,8 +29,7 @@ module Snowflaked
29
29
  end
30
30
 
31
31
  def machine_id_value
32
- id = @machine_id || default_machine_id
33
- id % (MAX_MACHINE_ID + 1)
32
+ (@machine_id || default_machine_id) % (MAX_MACHINE_ID + 1)
34
33
  end
35
34
 
36
35
  def epoch_ms
@@ -46,8 +45,7 @@ module Snowflaked
46
45
  end
47
46
 
48
47
  def env_machine_id
49
- id = ENV["SNOWFLAKED_MACHINE_ID"] || ENV.fetch("MACHINE_ID", nil)
50
- id&.to_i
48
+ (ENV["SNOWFLAKED_MACHINE_ID"] || ENV.fetch("MACHINE_ID", nil))&.to_i
51
49
  end
52
50
 
53
51
  def hostname_pid_hash
@@ -68,8 +66,8 @@ module Snowflaked
68
66
  end
69
67
 
70
68
  def id
71
- ensure_initialized!
72
- Native.generate
69
+ config = configuration
70
+ Native.generate(config.machine_id_value, config.epoch_ms)
73
71
  end
74
72
 
75
73
  def parse(id)
@@ -78,16 +76,17 @@ module Snowflaked
78
76
  end
79
77
 
80
78
  def timestamp(id)
81
- time_ms = Native.timestamp_ms(id)
82
- Time.at(time_ms / 1000, (time_ms % 1000) * 1000, :usec)
79
+ ensure_initialized!
80
+ seconds, milliseconds = Native.timestamp_ms(id).divmod(1000)
81
+ Time.at(seconds, milliseconds * 1000, :usec)
83
82
  end
84
83
 
85
84
  def machine_id(id)
86
- ensure_initialized!
87
85
  Native.machine_id(id)
88
86
  end
89
87
 
90
88
  def timestamp_ms(id)
89
+ ensure_initialized!
91
90
  Native.timestamp_ms(id)
92
91
  end
93
92
 
@@ -100,8 +99,7 @@ module Snowflaked
100
99
  def ensure_initialized!
101
100
  return if Native.initialized?
102
101
 
103
- config = configuration
104
- Native.init_generator(config.machine_id_value, config.epoch_ms)
102
+ Native.init_generator(configuration.machine_id_value, configuration.epoch_ms)
105
103
  end
106
104
  end
107
105
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snowflaked
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: arm-linux
6
6
  authors:
7
7
  - Luiz Eduardo Kowalski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-01-11 00:00:00.000000000 Z
11
+ date: 2026-02-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Ruby gem for generating Twitter Snowflake IDs using a high-performance
14
14
  Rust backend. Thread-safe with configurable machine ID and custom epoch support.