diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-07-04 01:41:24 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-07-04 01:41:24 +0800 |
commit | 1cecc285cfa7dfb3c34b34f07ab0b51c2a970bde (patch) | |
tree | db5cd7e4e9cedc03bdd402d8409fc390405a3b1b /doc/development | |
parent | 2c74e73f6f994346192acb2e723b026c2ec55f8b (diff) | |
parent | 68ac391435684352555ca5c4aca0e018face525a (diff) | |
download | gitlab-ce-add-ci_variables-environment_scope.tar.gz |
Merge remote-tracking branch 'upstream/master' into add-ci_variables-environment_scopeadd-ci_variables-environment_scope
* upstream/master: (79 commits)
Reset @full_path to nil when cache expires
add margin between captcha and register button
Eagerly create a milestone that is used in a feature spec
Adjust readme repo width
Resolve "Issue Board -> "Remove from board" button when viewing an issue gives js error and fails"
Fix rubocop offenses
Make entrypoint and command keys to be array of strings
Add issuable-list class to shared mr/issue lists to fix new responsive layout
New navigation breadcrumbs
Restore timeago translations in renderTimeago.
Fix curl example paths (missing the 'files' segment)
Automatically hide sidebar on smaller screens
Fix typo in IssuesFinder comment
Remove placeholder note when award emoji slash command is applied
Make setSidebarHeight more efficient with SidebarHeightManager.
Update CHANGELOG.md for 9.3.3
Resolve "More actions dropdown hidden by end of diff"
Use Gitaly 0.14.0
Improve support for external issue references
Make issuables_count_for_state public
...
Diffstat (limited to 'doc/development')
-rw-r--r-- | doc/development/README.md | 1 | ||||
-rw-r--r-- | doc/development/sha1_as_binary.md | 36 |
2 files changed, 37 insertions, 0 deletions
diff --git a/doc/development/README.md b/doc/development/README.md index 9496a87d84d..a2a07c37ced 100644 --- a/doc/development/README.md +++ b/doc/development/README.md @@ -54,6 +54,7 @@ - [Polymorphic Associations](polymorphic_associations.md) - [Single Table Inheritance](single_table_inheritance.md) - [Background Migrations](background_migrations.md) +- [Storing SHA1 Hashes As Binary](sha1_as_binary.md) ## i18n diff --git a/doc/development/sha1_as_binary.md b/doc/development/sha1_as_binary.md new file mode 100644 index 00000000000..3151cc29bbc --- /dev/null +++ b/doc/development/sha1_as_binary.md @@ -0,0 +1,36 @@ +# Storing SHA1 Hashes As Binary + +Storing SHA1 hashes as strings is not very space efficient. A SHA1 as a string +requires at least 40 bytes, an additional byte to store the encoding, and +perhaps more space depending on the internals of PostgreSQL and MySQL. + +On the other hand, if one were to store a SHA1 as binary one would only need 20 +bytes for the actual SHA1, and 1 or 4 bytes of additional space (again depending +on database internals). This means that in the best case scenario we can reduce +the space usage by 50%. + +To make this easier to work with you can include the concern `ShaAttribute` into +a model and define a SHA attribute using the `sha_attribute` class method. For +example: + +```ruby +class Commit < ActiveRecord::Base + include ShaAttribute + + sha_attribute :sha +end +``` + +This allows you to use the value of the `sha` attribute as if it were a string, +while storing it as binary. This means that you can do something like this, +without having to worry about converting data to the right binary format: + +```ruby +commit = Commit.find_by(sha: '88c60307bd1f215095834f09a1a5cb18701ac8ad') +commit.sha = '971604de4cfa324d91c41650fabc129420c8d1cc' +commit.save +``` + +There is however one requirement: the column used to store the SHA has _must_ be +a binary type. For Rails this means you need to use the `:binary` type instead +of `:text` or `:string`. |