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

Load taken urls from db instead of complete objects #182

Closed
wants to merge 2 commits into from
Closed

Load taken urls from db instead of complete objects #182

wants to merge 2 commits into from

Conversation

peritpatrio
Copy link

Premise

We have a scenario where there might be 1000 records in database with the same title. When saving the 1001st one, currently acts_as_urls loads 1000 records to see which number it should append to the end of the url slug. Naturally this causes some issues with memory when there are lots of records.

Changes made

This PR changes it so that only the url slugs are loaded into the memory rather than complete objects.

Few notes:

def url_owners
@url_owners ||= url_owners_class.all(:conditions => url_owner_conditions)
def taken_urls
@taken_urls ||= url_owners_class.all(:conditions => url_owner_conditions).pluck(settings.url_attribute)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [113/80]
Use the new Ruby 1.9 hash syntax.

@peritpatrio
Copy link
Author

Apparently running rake test did not run all tests.

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

Successfully merging this pull request may close these issues.

2 participants