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

unable to run performance tests with benchmark #50

Open
ewamarciniak opened this issue Aug 13, 2014 · 7 comments
Open

unable to run performance tests with benchmark #50

ewamarciniak opened this issue Aug 13, 2014 · 7 comments

Comments

@ewamarciniak
Copy link

Hi ,
I am trying to run rake test:benchmark which works with ActiveRecod but when I use it with Perrpetuity gem I get uninitialized constant Perpetuity::RailsModel (NameError). I tried adding 'require perpetuity' to the top of the test but it looks like it is not as simple. Is this something that can be fixed with minimal effort?
error

@jgaskins
Copy link
Owner

It looks like I need to add this to the README, but you'll want to add this line to config/initializers/perpetuity.rb. I noticed you had it in several places in your app. The benchmark is probably running in the test environment, which doesn't have the Perpetuity config in it. If you remove it from config/development.rb and put it in that initializer file, it will be loaded every time the app is initialized, regardless of the environment.

For a little background: The Perpetuity.data_source method is implemented in terms of Perpetuity.configure, which is where we do the Rails detection and Rails support is loaded (Perpetuity::RailsModel and several other Rails-specific things are not loaded at all if Rails isn't detected).

@ewamarciniak
Copy link
Author

Thanks Jamie, I will try that and let you know how this goes. One more question- and apologies if I have been asking too many. Probably no point in opening a new ticket: but It is about indexes. I have specified fields in the mapper files that I want the indexes to be set on. I know I need to reindex! at some point but not sure when this needs to be done. I have created a table and reindexed right after a table was created but as I look at my database in PgAdmin it doesn't look like any indexes have been applied. Any idea why this is not working for me? Thanks :)

@jgaskins
Copy link
Owner

If no indexes are being added, that's definitely a bug. The idea behind reindex! is that, after it's run, the indexes in the table should be exactly as you have them in the mapper; it removes any unspecified indexes and add indexes that aren't yet there.

The indexing code is not my favorite part of either this gem or perpetuity-postgres, so as much as I'd like to say it should be fine, it wouldn't surprise me if there's a bug there.

Which mapper is it so I can try to replicate the bug?

@ewamarciniak
Copy link
Author

Have a look at the Document mapper - I tried to add an index on the project and revision date . I try to reindex when I run a script that creates the tables (find it in folder script as for example db_script_small.rb).

@jgaskins
Copy link
Owner

I had a look at your Document mapper. It looks like the index isn't being created because it's trying to index the project attribute, which is stored in a JSON column, which doesn't allow BTREE indexes. Looks like I need to add detection for column type into the indexer. Indexes for JSON columns should probably be of type GIN by default.

@ewamarciniak
Copy link
Author

Thanks for having a look. I will wait for that My last question would be- I cannot find a join method. Are you planning on adding it?

@jgaskins
Copy link
Owner

I am, but it'll require quite a bit of work with the query parser. For example, given the following mappers:

Perpetuity.generate_mapper_for Article do
  # ...
  attribute :author, type: Person
end

Perpetuity.generate_mapper_for Person do
  attribute :name, type: String
end

What I'd like to do is to automatically do a join when you query based on another object's attributes:

Perpetuity[Article].select { |article| article.author.name == 'Jamie' }

This doesn't work yet for the Postgres adapter, but it does with the MongoDB adapter when embedding objects. When I implement joins, you'll be able to do queries like that. Since it will have the author loaded with JOIN, it'll also go ahead and store the author into the Article's author attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants