litestack 0.4.1 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.standard.yml +3 -0
  3. data/BENCHMARKS.md +23 -7
  4. data/CHANGELOG.md +35 -0
  5. data/Gemfile +1 -7
  6. data/README.md +124 -6
  7. data/ROADMAP.md +45 -0
  8. data/Rakefile +3 -1
  9. data/WHYLITESTACK.md +1 -1
  10. data/assets/litecache_metrics.png +0 -0
  11. data/assets/litedb_metrics.png +0 -0
  12. data/assets/litemetric_logo_teal.png +0 -0
  13. data/assets/litesearch_logo_teal.png +0 -0
  14. data/bench/bench.rb +17 -10
  15. data/bench/bench_cache_rails.rb +45 -14
  16. data/bench/bench_cache_raw.rb +44 -28
  17. data/bench/bench_jobs_rails.rb +18 -12
  18. data/bench/bench_jobs_raw.rb +17 -10
  19. data/bench/bench_queue.rb +4 -6
  20. data/bench/rails_job.rb +5 -7
  21. data/bench/skjob.rb +4 -4
  22. data/bench/uljob.rb +6 -6
  23. data/bin/liteboard +2 -1
  24. data/lib/action_cable/subscription_adapter/litecable.rb +5 -8
  25. data/lib/active_job/queue_adapters/litejob_adapter.rb +6 -8
  26. data/lib/active_record/connection_adapters/litedb_adapter.rb +72 -84
  27. data/lib/active_support/cache/litecache.rb +61 -41
  28. data/lib/generators/litestack/install/install_generator.rb +3 -3
  29. data/lib/generators/litestack/install/templates/cable.yml +0 -3
  30. data/lib/generators/litestack/install/templates/database.yml +7 -1
  31. data/lib/litestack/liteboard/liteboard.rb +269 -149
  32. data/lib/litestack/litecable.rb +41 -37
  33. data/lib/litestack/litecable.sql.yml +22 -11
  34. data/lib/litestack/litecache.rb +118 -93
  35. data/lib/litestack/litecache.sql.yml +83 -22
  36. data/lib/litestack/litecache.yml +1 -1
  37. data/lib/litestack/litedb.rb +35 -40
  38. data/lib/litestack/litejob.rb +30 -29
  39. data/lib/litestack/litejobqueue.rb +63 -65
  40. data/lib/litestack/litemetric.rb +80 -92
  41. data/lib/litestack/litemetric.sql.yml +244 -234
  42. data/lib/litestack/litemetric_collector.sql.yml +38 -41
  43. data/lib/litestack/litequeue.rb +39 -41
  44. data/lib/litestack/litequeue.sql.yml +39 -31
  45. data/lib/litestack/litescheduler.rb +24 -18
  46. data/lib/litestack/litesearch/index.rb +93 -63
  47. data/lib/litestack/litesearch/model.rb +66 -65
  48. data/lib/litestack/litesearch/schema.rb +53 -56
  49. data/lib/litestack/litesearch/schema_adapters/backed_adapter.rb +46 -50
  50. data/lib/litestack/litesearch/schema_adapters/basic_adapter.rb +44 -35
  51. data/lib/litestack/litesearch/schema_adapters/contentless_adapter.rb +3 -6
  52. data/lib/litestack/litesearch/schema_adapters/standalone_adapter.rb +7 -9
  53. data/lib/litestack/litesearch/schema_adapters.rb +4 -9
  54. data/lib/litestack/litesearch.rb +6 -9
  55. data/lib/litestack/litesupport.rb +78 -87
  56. data/lib/litestack/railtie.rb +1 -1
  57. data/lib/litestack/version.rb +2 -2
  58. data/lib/litestack.rb +6 -4
  59. data/lib/railties/rails/commands/dbconsole.rb +16 -20
  60. data/lib/sequel/adapters/litedb.rb +16 -21
  61. data/lib/sequel/adapters/shared/litedb.rb +168 -168
  62. data/scripts/build_metrics.rb +91 -0
  63. data/scripts/test_cable.rb +30 -0
  64. data/scripts/test_job_retry.rb +33 -0
  65. data/scripts/test_metrics.rb +60 -0
  66. data/template.rb +2 -2
  67. metadata +115 -7
@@ -3,23 +3,21 @@ require "active_support/core_ext/enumerable"
3
3
  require "active_support/core_ext/array/extract_options"
4
4
  require "active_support/core_ext/numeric/time"
5
5
  require "active_support/cache"
6
- require_relative '../../litestack'
7
-
6
+ require_relative "../../litestack/litecache"
8
7
 
9
8
  module ActiveSupport
10
9
  module Cache
11
10
  class Litecache < Store
11
+ #prepend Strategy::LocalCache
12
12
 
13
- prepend Strategy::LocalCache
14
-
15
13
  def self.supports_cache_versioning?
16
14
  true
17
15
  end
18
16
 
19
- def initialize(options={})
17
+ def initialize(options = {})
20
18
  super
21
19
  @options[:return_full_record] = true
22
- @cache = ::Litecache.new(@options) # reachout to the outer litecache class
20
+ @cache = ::Litecache.new(@options) # reachout to the outer litecache class
23
21
  end
24
22
 
25
23
  def increment(key, amount = 1, options = nil)
@@ -27,39 +25,44 @@ module ActiveSupport
27
25
  options = merged_options(options)
28
26
  # todo: fix me
29
27
  # this is currently a hack to avoid dealing with Rails cache encoding and decoding
30
- #@cache.transaction(:immediate) do
31
- if value = read(key, options)
32
- value = value.to_i + amount
33
- write(key, value, options)
34
- end
35
- #end
28
+ # and it can result in a race condition as it stands
29
+ # @cache.transaction(:immediate) do
30
+ # currently transactions are not compatible with acquiring connections
31
+ # this needs fixing by storing the connection to the context once acquired
32
+ if (value = read(key, options))
33
+ value = value.to_i + amount
34
+ write(key, value, options)
35
+ else
36
+ write(key, amount, options)
37
+ end
38
+ # end
36
39
  end
37
40
 
38
41
  def decrement(key, amount = 1, options = nil)
39
42
  options = merged_options(options)
40
- increment(key, -1 * amount, options[:expires_in])
43
+ increment(key, -1 * amount, options)
41
44
  end
42
-
45
+
43
46
  def prune(limit = nil, time = nil)
44
47
  @cache.prune(limit)
45
48
  end
46
49
 
47
50
  def cleanup(limit = nil, time = nil)
48
51
  @cache.prune(limit)
49
- end
52
+ end
50
53
 
51
- def clear(options = nil)
52
- @cache.clear
54
+ def clear(options=nil)
55
+ @cache.clear
53
56
  end
54
-
57
+
55
58
  def count
56
59
  @cache.count
57
60
  end
58
-
61
+
59
62
  def size
60
63
  @cache.size
61
64
  end
62
-
65
+
63
66
  def max_size
64
67
  @cache.max_size
65
68
  end
@@ -70,33 +73,50 @@ module ActiveSupport
70
73
 
71
74
  private
72
75
 
73
- # Read an entry from the cache.
74
- def read_entry(key, **options)
75
- deserialize_entry(@cache.get(key))
76
- end
76
+ # Read an entry from the cache.
77
+ def read_entry(key, **options)
78
+ deserialize_entry(@cache.get(key))
79
+ end
77
80
 
78
- # Write an entry to the cache.
79
- def write_entry(key, entry, **options)
80
- write_serialized_entry(key, serialize_entry(entry, **options), **options)
81
+ def read_multi_entries(names, **options)
82
+ results = {}
83
+ return results if names == []
84
+ rs = @cache.get_multi(*names.flatten)
85
+ rs.each_pair{|k, v| results[k] = deserialize_entry(v).value }
86
+ results
87
+ end
88
+
89
+ # Write an entry to the cache.
90
+ def write_entry(key, entry, **options)
91
+ write_serialized_entry(key, serialize_entry(entry, **options), **options)
92
+ end
93
+
94
+ def write_multi_entries(entries, **options)
95
+ return if entries.empty?
96
+ entries.each_pair {|k,v| entries[k] = serialize_entry(v, **options)}
97
+ expires_in = options[:expires_in].to_i
98
+ if options[:race_condition_ttl] && expires_in > 0 && !options[:raw]
99
+ expires_in += 5.minutes
81
100
  end
101
+ @cache.set_multi(entries, expires_in)
102
+ end
82
103
 
83
- def write_serialized_entry(key, payload, **options)
84
- expires_in = options[:expires_in].to_i
85
- if options[:race_condition_ttl] && expires_in > 0 && !options[:raw]
86
- expires_in += 5.minutes
87
- end
88
- if options[:unless_exist]
89
- @cache.set_unless_exists(key, payload, expires_in)
90
- else
91
- @cache.set(key, payload, expires_in)
92
- end
104
+ def write_serialized_entry(key, payload, **options)
105
+ expires_in = options[:expires_in].to_i
106
+ if options[:race_condition_ttl] && expires_in > 0 && !options[:raw]
107
+ expires_in += 5.minutes
93
108
  end
94
-
95
- # Delete an entry from the cache.
96
- def delete_entry(key, **options)
97
- return @cache.delete(key)
109
+ if options[:unless_exist]
110
+ @cache.set_unless_exists(key, payload, expires_in)
111
+ else
112
+ @cache.set(key, payload, expires_in)
98
113
  end
114
+ end
99
115
 
116
+ # Delete an entry from the cache.
117
+ def delete_entry(key, **options)
118
+ @cache.delete(key)
119
+ end
100
120
  end
101
121
  end
102
122
  end
@@ -27,9 +27,9 @@ class Litestack::InstallGenerator < Rails::Generators::Base
27
27
  def modify_gitignore
28
28
  append_file ".gitignore", <<~TEXT
29
29
 
30
- # Ignore default Litestack SQLite databases.
31
- /db/**/*.sqlite3
32
- /db/**/*.sqlite3-*
30
+ # Ignore default Litestack SQLite databases.
31
+ /db/**/*.sqlite3
32
+ /db/**/*.sqlite3-*
33
33
  TEXT
34
34
  end
35
35
  end
@@ -4,8 +4,5 @@ development:
4
4
  test:
5
5
  adapter: test
6
6
 
7
- staging:
8
- adapter: litecable
9
-
10
7
  production:
11
8
  adapter: litecable
@@ -7,6 +7,9 @@
7
7
  # `Litesupport.root.join("data.sqlite3")` stores
8
8
  # application data in the path `./db/#{Rails.env}/data.sqlite3`
9
9
  #
10
+ # `Litesupport.root(env).join(path)` stores
11
+ # application data in the path `./db/#{env}/#{path}`
12
+ #
10
13
  # idle_timeout should be set to zero, to avoid recycling sqlite connections
11
14
  # and losing the page cache
12
15
  #
@@ -14,16 +17,17 @@ default: &default
14
17
  adapter: litedb
15
18
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
16
19
  idle_timeout: 0
17
- database: <%= Litesupport.root.join("data.sqlite3") %>
18
20
 
19
21
  development:
20
22
  <<: *default
23
+ database: <%= Litesupport.root("development").join("data.sqlite3") %>
21
24
 
22
25
  # Warning: The database defined as "test" will be erased and
23
26
  # re-generated from your development database when you run "rake".
24
27
  # Do not set this db to the same as development or production.
25
28
  test:
26
29
  <<: *default
30
+ database: <%= Litesupport.root("test").join("data.sqlite3") %>
27
31
 
28
32
  # Warning: Make sure your production database path is on a persistent
29
33
  # volume, otherwise your application data could be deleted between deploys.
@@ -32,3 +36,5 @@ test:
32
36
  # `LITESTACK_DATA_PATH` environment variable.
33
37
  production:
34
38
  <<: *default
39
+ database: <%= Litesupport.root("production").join("data.sqlite3") %>
40
+