Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b1f75a22
Commit
b1f75a22
authored
Oct 27, 2020
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'default-oj' into 'master'
Remove :oj_json feature flag See merge request gitlab-org/gitlab!46012
parents
cb4ec474
7d57c135
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
236 additions
and
325 deletions
+236
-325
config/feature_flags/development/oj_json.yml
config/feature_flags/development/oj_json.yml
+0
-7
lib/gitlab/json.rb
lib/gitlab/json.rb
+6
-30
spec/lib/gitlab/json_spec.rb
spec/lib/gitlab/json_spec.rb
+230
-288
No files found.
config/feature_flags/development/oj_json.yml
deleted
100644 → 0
View file @
cb4ec474
---
name
:
oj_json
introduced_by_url
:
rollout_issue_url
:
group
:
type
:
development
default_enabled
:
true
lib/gitlab/json.rb
View file @
b1f75a22
...
...
@@ -67,15 +67,6 @@ module Gitlab
::
JSON
.
pretty_generate
(
object
,
opts
)
end
# Feature detection for using Oj instead of the `json` gem.
#
# @return [Boolean]
def
enable_oj?
return
false
unless
feature_table_exists?
Feature
.
enabled?
(
:oj_json
,
default_enabled:
true
)
end
private
# Convert JSON string into Ruby through toggleable adapters.
...
...
@@ -91,11 +82,7 @@ module Gitlab
def
adapter_load
(
string
,
*
args
,
**
opts
)
opts
=
standardize_opts
(
opts
)
if
enable_oj?
Oj
.
load
(
string
,
opts
)
else
::
JSON
.
parse
(
string
,
opts
)
end
rescue
Oj
::
ParseError
,
Encoding
::
UndefinedConversionError
=>
ex
raise
parser_error
.
new
(
ex
)
end
...
...
@@ -120,11 +107,7 @@ module Gitlab
#
# @return [String]
def
adapter_dump
(
object
,
*
args
,
**
opts
)
if
enable_oj?
Oj
.
dump
(
object
,
opts
)
else
::
JSON
.
dump
(
object
,
*
args
)
end
end
# Generates JSON for an object but with fewer options, using toggleable adapters.
...
...
@@ -135,11 +118,7 @@ module Gitlab
def
adapter_generate
(
object
,
opts
=
{})
opts
=
standardize_opts
(
opts
)
if
enable_oj?
Oj
.
generate
(
object
,
opts
)
else
::
JSON
.
generate
(
object
,
opts
)
end
end
# Take a JSON standard options hash and standardize it to work across adapters
...
...
@@ -149,11 +128,8 @@ module Gitlab
# @return [Hash]
def
standardize_opts
(
opts
)
opts
||=
{}
if
enable_oj?
opts
[
:mode
]
=
:rails
opts
[
:symbol_keys
]
=
opts
[
:symbolize_keys
]
||
opts
[
:symbolize_names
]
end
opts
end
...
...
@@ -213,7 +189,7 @@ module Gitlab
# @param object [Object]
# @return [String]
def
self
.
call
(
object
,
env
=
nil
)
if
Gitlab
::
Json
.
enable_oj?
&&
Feature
.
enabled?
(
:grape_gitlab_json
,
default_enabled:
true
)
if
Feature
.
enabled?
(
:grape_gitlab_json
,
default_enabled:
true
)
Gitlab
::
Json
.
dump
(
object
)
else
Grape
::
Formatter
::
Json
.
call
(
object
,
env
)
...
...
spec/lib/gitlab/json_spec.rb
View file @
b1f75a22
...
...
@@ -7,7 +7,6 @@ RSpec.describe Gitlab::Json do
stub_feature_flags
(
json_wrapper_legacy_mode:
true
)
end
shared_examples
"json"
do
describe
".parse"
do
context
"legacy_mode is disabled by default"
do
it
"parses an object"
do
...
...
@@ -295,12 +294,6 @@ RSpec.describe Gitlab::Json do
subject
.
send
(
:handle_legacy_mode!
,
{})
end
it
"skips oj feature detection"
do
expect
(
Feature
).
not_to
receive
(
:enabled?
).
with
(
:oj_json
,
default_enabled:
true
)
subject
.
send
(
:enable_oj?
)
end
end
context
"the database is missing"
do
...
...
@@ -316,35 +309,6 @@ RSpec.describe Gitlab::Json do
expect
(
subject
.
dump
({})).
to
eq
(
"{}"
)
end
end
end
context
"oj gem"
do
before
do
stub_feature_flags
(
oj_json:
true
)
end
it_behaves_like
"json"
describe
"#enable_oj?"
do
it
"returns true"
do
expect
(
subject
.
enable_oj?
).
to
be
(
true
)
end
end
end
context
"json gem"
do
before
do
stub_feature_flags
(
oj_json:
false
)
end
it_behaves_like
"json"
describe
"#enable_oj?"
do
it
"returns false"
do
expect
(
subject
.
enable_oj?
).
to
be
(
false
)
end
end
end
describe
Gitlab
::
Json
::
GrapeFormatter
do
subject
{
described_class
.
call
(
obj
,
env
)
}
...
...
@@ -353,11 +317,6 @@ RSpec.describe Gitlab::Json do
let
(
:env
)
{
{}
}
let
(
:result
)
{
"{
\"
test
\"
:true}"
}
context
"oj is enabled"
do
before
do
stub_feature_flags
(
oj_json:
true
)
end
context
"grape_gitlab_json flag is enabled"
do
before
do
stub_feature_flags
(
grape_gitlab_json:
true
)
...
...
@@ -391,23 +350,6 @@ RSpec.describe Gitlab::Json do
end
end
context
"oj is disabled"
do
before
do
stub_feature_flags
(
oj_json:
false
)
end
it
"generates JSON"
do
expect
(
subject
).
to
eq
(
result
)
end
it
"uses Grape::Formatter::Json"
do
expect
(
Grape
::
Formatter
::
Json
).
to
receive
(
:call
).
with
(
obj
,
env
)
subject
end
end
end
describe
Gitlab
::
Json
::
LimitedEncoder
do
subject
{
described_class
.
encode
(
obj
,
limit:
8
.
kilobytes
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment