5 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -183,7 +183,7 @@ def self.invalid_credentials?(error, _context = {})
183
183
# should not happen as we proactively check for record size before pushing
184
184
# them. If it still happens it means that the value set in max_record_size
185
185
# is not matching the value in the plan.
186
- def self . record_too_big_api? ( error , _contex = { } )
186
+ def self . record_too_big_api? ( error , _context = { } )
187
187
details = error_hash ( error . message )
188
188
return false if details == false
189
189
Original file line number Diff line number Diff line change @@ -54,13 +54,20 @@ def self.add_unique_object_id(record)
54
54
#
55
55
# content - The HTML content to parse
56
56
def self . extract_raw_records ( content )
57
- AlgoliaHTMLExtractor . run (
57
+ records = AlgoliaHTMLExtractor . run (
58
58
content ,
59
59
options : {
60
60
css_selector : Configurator . algolia ( 'nodes_to_index' ) ,
61
61
tags_to_exclude : 'script,style,iframe'
62
62
}
63
63
)
64
+ # We remove objectIDs, as the will be added at the very end, after all
65
+ # the hooks and shrinkage
66
+ records . each do |record |
67
+ record . delete ( :objectID )
68
+ end
69
+
70
+ records
64
71
end
65
72
end
66
73
end
Original file line number Diff line number Diff line change @@ -346,7 +346,7 @@ def self.set_settings(settings)
346
346
# their dashboard
347
347
#
348
348
# When users change some settings in their dashboard, those settings might
349
- # get overwritten by the pluging . We can't prevent that, but we can warn
349
+ # get overwritten by the plugin . We can't prevent that, but we can warn
350
350
# them when we detect they changed something.
351
351
def self . warn_of_manual_dashboard_editing ( changed_keys )
352
352
# Transform the hash into readable YAML
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ module Shrinker
10
10
# Public: Get the byte size of the object once converted to JSON
11
11
# - record: The record to estimate
12
12
def self . size ( record )
13
- record . to_json . length
13
+ record . to_json . bytesize
14
14
end
15
15
16
16
# Public: Attempt to reduce the size of the record by reducing the size of
@@ -33,7 +33,7 @@ def self.fit_to_size(raw_record, max_size)
33
33
record [ :excerpt_html ] = record [ :excerpt_text ]
34
34
return record if size ( record ) <= max_size
35
35
36
- # We halve the excerpts
36
+ # We half the excerpts
37
37
excerpt_words = record [ :excerpt_text ] . split ( /\s +/ )
38
38
shortened_excerpt = excerpt_words [ 0 ...excerpt_words . size / 2 ] . join ( ' ' )
39
39
record [ :excerpt_text ] = shortened_excerpt
Original file line number Diff line number Diff line change 16
16
it { should eq 2 }
17
17
end
18
18
19
- describe 'should return a size in bytes ' do
19
+ describe 'should return the size if no special chars ' do
20
20
let ( :input ) { { foo : 'bar' } }
21
21
it { should eq 13 }
22
22
end
23
+
24
+ describe 'should return a size in bytes, even with UTF-8 chars' do
25
+ let ( :input ) { { foo : '“æé' } }
26
+ it { should eq 17 }
27
+ end
23
28
end
24
29
25
30
describe '.fit_to_size' do
0 commit comments