Skip to content
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

Issue with the command to sync the indexes #255

Open
arabakevin opened this issue Nov 5, 2019 · 13 comments
Open

Issue with the command to sync the indexes #255

arabakevin opened this issue Nov 5, 2019 · 13 comments
Labels
enhancement Improve what already exist.

Comments

@arabakevin
Copy link

Hi,
i have two models
my first one is "Organiasation"

# frozen_string_literal: true

# @author kzvdev
# Organisation model
class Organisation
  include NoBrainer::Document
  include NoBrainer::Document::Timestamps
  include HasSlug

  # ~~~~ Virtual Fields ~~~~
  attr_accessor :remove_logo

  # ~~~~ Fieds ~~~~~
  field :name, type: String, uniq: true, required: true
  field :logo, type: String
  field :postal_code, type: String
  field :city, type: String
  field :street, type: String
  field :email, type: String
  field :billing_email, type: String
  field :slug, type: String, uniq: true, required: true

  # ~~~~ Special Behaviors ~~~~
  mount_uploader :logo, LogoUploader

  # ~~~~ Associations ~~~~
  belongs_to :created_by_user, class_name: 'User'
  belongs_to :country, validates: false
  has_many :clients
  has_many :ideas
  has_many :join_requests
  has_many :notifications
  has_many :projects
  has_many :tags
  has_many :users

  # Simple index
  index :name

  def to_param
    slug
  end
end

And a second who is named "Project"

# frozen_string_literal: true

# @author kzvdev
# Project model
class Project
  include NoBrainer::Document
  include NoBrainer::Document::Timestamps
  include AASM
  include HasSlug

  # ~~~~ Virtual Fields ~~~~
  attr_accessor :remove_picture

  # ~~~~ Fieds ~~~~~
  field :logo, type: String
  field :name, type: String, required: true, uniq: { scope: :organisation_id }
  field :organisation_id, type: String
  field :created_by_user_id, type: String
  field :slug, type: String, uniq: true, required: true
  field :state, type: String

  # ~~~~ Associations ~~~~
  belongs_to :created_by_user, class_name: 'User'
  belongs_to :organisation
  has_many :ideas

  # Simple index
  index :name

  # ~~~~ Special Behaviors ~~~~
  mount_uploader :logo, LogoUploader

  aasm column: 'state' do
    state :active, initial: true
    state :archived

    event :mark_as_archive do
      transitions from: :active, to: :archived
    end
    event :mark_as_unarchive do
      transitions from: :archived, to: :active
    end
  end

  # @nodoc ~~~~ Scopes ~~~~
  scope :active, -> { where(state: "active") }

  def to_param
    slug
  end
end

So, in the both models i have one index. When i started with an empty database.
And i use this command to sync the indexes:

rake nobrainer:sync_indexes

i can see only one index created and this one is only the index of Organisation and the index of the second model is not created.

Thanks.
Regards.
kevin

@nviennot
Copy link
Collaborator

nviennot commented Nov 6, 2019

Hey Kevin,

I tried your code (well, without the mount, and aasm and the like). See here: https://gist.github.com/nviennot/9f636ff7ce952ec9e10001e0aabd7a4a

When I run ruby test255.rb, I see in the console the two indexes being created:

D, [2019-11-05T21:59:18.682787 #50235] DEBUG -- : [  24.1ms] r.table("organisations").index_create(:name) {|var_1| var_1[:name]}
D, [2019-11-05T21:59:18.738029 #50235] DEBUG -- : [  36.9ms] r.table("projects").index_create(:name) {|var_1| var_1[:name]}

Edit: I'm guessing the model where the index does not appear might not be loaded. Verify tha the model is loaded (you can debug this by putting a puts "hello" in the model file in equestion.

@arabakevin
Copy link
Author

ok thanks. I will test again as soon as possible with your example.

@arabakevin
Copy link
Author

Hi,
So, i have retested a new time and on my side i have only one index created. I use Docker do you think it's here the issue ?

The puts "hello" working properly.

Which information can i provide you to help me again ?

Thanks for your help.
kevin

@nviennot
Copy link
Collaborator

Create the smallest test case that is able to reproduce the bug, and then I'll be able to help

@arabakevin
Copy link
Author

arabakevin commented Nov 13, 2019

Hi, as discussed I have created a test repository to help you to reproduce more easily my issue.
So, you can find how to reproduce the issue here --> https://github.com/arabakevin/nobrainer-issue-255

Thanks.
Cheers.
Kevin

@zedtux
Copy link
Collaborator

zedtux commented Nov 18, 2019

Hey @nviennot,

I'm also looking for this issue too. Could you please give your input?

Thank you.

@extem
Copy link

extem commented Nov 18, 2019

In Rails6, the model may not be loaded during development because the autoloader specification has changed.
I solved the problem by setting
config.autoloader = :classic

@zedtux
Copy link
Collaborator

zedtux commented Nov 19, 2019

Thank you @extem, I'll try that.

@arabakevin
Copy link
Author

Hi @extem ,
Thanks for your help i have tested and it's working properly on my side.

Capture d’écran 2019-11-19 à 20 58 39

We can close this issue for me.

kevin.

@zedtux
Copy link
Collaborator

zedtux commented Nov 20, 2019

@nviennot should the documentation be updated with this option? And the nobrainer post install script to add this option?

@nviennot
Copy link
Collaborator

It's probably best to invoke the eager loading of the models (e.g., Zeitwerk::Loader.eager_load_all) when the models should be loaded.
In particular, https://github.com/nviennot/nobrainer/blob/master/lib/no_brainer/document/core.rb#L28 should work

@zedtux
Copy link
Collaborator

zedtux commented Nov 22, 2019

Yes, but I'm more thinking of nobrainer working out-of-the-box with Rails 6.

@nviennot
Copy link
Collaborator

Me too, NoBrainer should invoke the proper rails incantation to make sure all models are loaded when needed

@zedtux zedtux added the enhancement Improve what already exist. label Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve what already exist.
Projects
None yet
Development

No branches or pull requests

4 participants