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

Remove squeel queries from codebase #2283

Merged

Conversation

weiqingtoh
Copy link
Member

Starts #2271. Squeel is not being maintained now, hence removing all dependencies on it would be useful.

This PR removes all Squeel queries from Coursemology, and replaces them with vanilla ActiveRecord and baby_squeel (aimed at replacing Squeel, without monkey-patching ActiveRecord). For most parts, I've opted to stick to normal Activerecord to ensure easier upgrade paths in the future.

Note that however, cancancan-squeel, which has a dependency on squeel, is still installed. This is because the cancancan-squeel adapter does fix certain issues with self-joins and calculated attributes which is still necessary for Coursemology to function. The next step is to work on an alternative for that adapter.

end

def ended
where { (end_at == nil) | (end_at >= Time.zone.now) }
where.has { (end_at == nil) | (end_at >= Time.zone.now) }

Choose a reason for hiding this comment

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

Prefer the use of the nil? predicate.

@@ -8,11 +8,11 @@ def currently_active
private

def started
where { (start_at == nil) | (start_at <= Time.zone.now) }
where.has { (start_at == nil) | (start_at <= Time.zone.now) }

Choose a reason for hiding this comment

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

Prefer the use of the nil? predicate.

merge(Course::GroupUser.normal).
where { group_users.group_id == group_id }
course.course_users.joins(:group_users).where('course_group_users.group_id = ?', group_id)
merge(Course::GroupUser.normal)

Choose a reason for hiding this comment

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

Inconsistent indentation detected.

@experience_points_records.active.includes { actable }.
includes(:updater).order(updated_at: :desc).page(page_param)
@experience_points_records.active.includes(:actable, :updater).order(updated_at: :desc).
page(page_param)

Choose a reason for hiding this comment

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

Align page with @experience_points_records.active.includes(:actable, :updater).order(updated_at: :desc). on line 16.

- Previously, renderComponent(response.data) was called before the document was ready.
merge(Course::GroupUser.normal).
where { group_users.group_id == group_id }
course.course_users.joins(:group_users).where('course_group_users.group_id = ?', group_id).
merge(Course::GroupUser.normal)

Choose a reason for hiding this comment

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

Use 2 (not 0) spaces for indenting an expression spanning multiple lines.

- This commit attempts to remove most of squeel APIs. However, note that squeel is still bundled as part of the cancancan-squeel, which fixes some of Coursemology's cancancan issues (self-joins, etc).
- The changes are aimed at using pure ActiveRecord methods which enables easier upgrading in the future. In cases where AR is insufficient, baby_squeel is used.
@allenwq
Copy link
Member

allenwq commented May 12, 2017

👍

@allenwq allenwq merged commit e4b7471 into Coursemology:master May 12, 2017
@weiqingtoh weiqingtoh deleted the weiqingtoh/baby-squeel branch May 12, 2017 09:36
@weiqingtoh weiqingtoh mentioned this pull request Sep 23, 2017
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants