Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
d774c4a7
Unverified
Commit
d774c4a7
authored
7 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Use new Toucan select-reducible for updating Field/Table display names
parent
eb3c5261
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
project.clj
+1
-1
1 addition, 1 deletion
project.clj
src/metabase/models/humanization.clj
+11
-21
11 additions, 21 deletions
src/metabase/models/humanization.clj
with
12 additions
and
22 deletions
project.clj
+
1
−
1
View file @
d774c4a7
...
...
@@ -98,7 +98,7 @@
[
ring/ring-jetty-adapter
"1.6.0"
]
; Ring adapter using Jetty webserver (used to run a Ring server for unit tests)
[
ring/ring-json
"0.4.0"
]
; Ring middleware for reading/writing JSON automatically
[
stencil
"0.5.0"
]
; Mustache templates for Clojure
[
toucan
"1.1.
2
"
; Model layer, hydration, and DB utilities
[
toucan
"1.1.
4
"
; Model layer, hydration, and DB utilities
:exclusions
[
honeysql
]]]
:repositories
[[
"bintray"
"https://dl.bintray.com/crate/crate"
]
; Repo for Crate JDBC driver
[
"redshift"
"https://s3.amazonaws.com/redshift-driver-downloads"
]]
...
...
This diff is collapsed.
Click to expand it.
src/metabase/models/humanization.clj
+
11
−
21
View file @
d774c4a7
...
...
@@ -79,27 +79,17 @@
(
vals
(
methods
name->human-readable-name
)))))
(
defn-
re-humanize-names!
"Update all non-custom display names of all instances of `model` (e.g. Table or Field). To prevent explosions on very
large instances this is done in chunks of 10000 IDs at a time"
;; TODO - once Toucan has the new streaming SELECT functions we can use those instead of manually chunking
;; TODO - Alternatively, just make this chunking pattern generic and add to Toucan. Could be useful elsewhere!
([
model
]
(
re-humanize-names!
model
0
))
([
model
starting-id
]
(
let
[
chunk-size
10000
]
(
when-let
[
instances
(
seq
(
db/select
[
model
:id
:name
:display_name
]
:id
[
:>=
starting-id
]
{
:limit
chunk-size
}))]
(
doseq
[{
id
:id,
internal-name
:name,
display-name
:display_name
}
instances
:let
[
new-display-name
(
name->human-readable-name
internal-name
)]
:when
(
and
(
not=
display-name
new-display-name
)
(
not
(
custom-display-name?
internal-name
display-name
)))]
(
log/info
(
format
"Updating display name for %s '%s': '%s' -> '%s'"
(
name
model
)
internal-name
display-name
new-display-name
))
(
db/update!
model
id
:display_name
new-display-name
))
;; if we got a full chunk, do the next chunk, starting at one past the ID of the last object
(
when
(
>=
(
count
instances
)
chunk-size
)
(
recur
model
(
inc
(
:id
(
last
instances
)))))))))
"Update all non-custom display names of all instances of `model` (e.g. Table or Field)."
[
model
]
(
run!
(
fn
[{
id
:id,
internal-name
:name,
display-name
:display_name
}]
(
let
[
new-display-name
(
name->human-readable-name
internal-name
)]
(
when
(
and
(
not=
display-name
new-display-name
)
(
not
(
custom-display-name?
internal-name
display-name
)))
(
log/info
(
format
"Updating display name for %s '%s': '%s' -> '%s'"
(
name
model
)
internal-name
display-name
new-display-name
))
(
db/update!
model
id
:display_name
new-display-name
))))
(
db/select-reducible
[
model
:id
:name
:display_name
])))
(
defn-
re-humanize-table-and-field-names!
"Update the non-custom display names of all Tables & Fields in the database using new values obtained from
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment