-
Notifications
You must be signed in to change notification settings - Fork 16
Домашнее задание 2 #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| gem 'slim-rails' | ||
|
|
||
| # Serializers | ||
| gem 'jbuilder' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Традиционно выбрал бы вместо jbuilder, что-то по-шустрее: он когда разрастется и обрастет логикой, его потом трудно заменять. Но про это уже писал в первом задании
| config/environments/*.local.yml | ||
|
|
||
| # IDE files | ||
| /.idea/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отлично!
| INDEX_CONCURRENT_PROCESSES= | ||
|
|
||
| MONGO_HOST=mongo | ||
| MONGO_PORT=27017 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отлично! Не забыли добавить переменные окружения в .sample.env (вы единственный кто это сделал )))
| gem 'devise' | ||
|
|
||
| # Паджинация | ||
| gem 'kaminari-mongoid' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отлично!
| field :published_at, type: Date | ||
| field :insno, type: String | ||
| field :folder_id, type: String | ||
| field :language_id, type: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отлично! Скрупулезно перечислены атрибуты
| @@ -0,0 +1,19 @@ | |||
| module Mongo | |||
| class BookMongo | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если модель вызывать где-то в коде, то получается не очень красиво: Mongo::BookMongo - два раза Mongo. И вообще лучше как-то переименовать, чтобы в названии не было отсылки к MongoDB. Вдруг потом захотим сменить базу данных на ElasticSearch а название уже расползется по всему проекту. Это конечно, не большая проблема с современными IDE, но все-равно лучше какое-нибудь бизнесовое название BookSource или Documents::Book. Потом копипастой эта Mongo расползется по всем моделям, и каждая модель будет "кричать" что она от MongoDB, вместо того, чтобы "кричать" о своем бизнес-назначении или домене. Это не проблема в маленьком приложении, но если моделей 100 и все они говорят, что они работают с MongoDB - это утомляет, хочется узнать, а чем эти 100 моделей друг от друга отличаются.
| username: <%= ENV.fetch('POSTGRES_USER') { 'igorsimdyanov' } %> | ||
| password: <%= ENV.fetch('POSTGRES_PASSWORD') { '' } %> | ||
| username: <%= ENV.fetch('POSTGRES_USER') { 'postgres' } %> | ||
| password: <%= ENV.fetch('postgres') { '' } %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут явно опечатка, если потом захотите сменить пароль - будут проблемы. Писал об этом в первом мердж-реквесте, но понимаю, что не успели поправить (почти одновременно отправили).
|
|
||
| test: | ||
| <<: *default | ||
| <<: *postgre |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Очень хорошо!
| ports: | ||
| - "27017:27017" | ||
| volumes: | ||
| - mongo_data:/data/db |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отлично, что модифицировали docker-compose.yml.
| # Получаем все книги из PostgreSQL | ||
| books = pg_connection.execute("SELECT * FROM books") | ||
|
|
||
| books.each do |book| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше все-таки воспользоваться batch-вариантом переноса данных, т.е. переносить кусочками по 1 000 или 10 000 книг. Иначе вы сначала выгружаете гигантский массив моделей в оперативную память и лишь потом начинаете книгу за книгой переносить в Mongo. Все это время память занята, а вам ведь все 800 000 книг в памяти на не требуются. Причем в ActiveRecord даже такая возможность уже есть https://api.rubyonrails.org/classes/ActiveRecord/Batches.html
Books.in_batches do |book|
...
end
No description provided.