Explain Strategy Pattern and create an example
4- What are some best practices to prevent memory leaks in a Rails application?
class WeeklyEmailJob < ApplicationJob
queue_as :default
def perform
User.find_each do |user|
UserMailer.weekly_email(user).deliver_now
end
3- Explain how you would implement a caching strategy for a page that shows the most recent posts to reduce database load.
-
3.1- Explain fragment Caching
<table> <thead> <tr> <th>Title</th> <th>Description</th>
2- Indexing Strategy You have a Post model with a large number of records. Explain how you would determine which columns to index and how to implement these indexes.
create_table :posts do |t|
t.string :title
t.integer :user_id
t.text :text
1- You have a User model with thousands of records. There is an existing query that performs a full table scan, causing significant performance issues. The query looks like this:
users = User.all.select { |user| user.created_at > 1.year.ago && user.active? }
Tasks:
Identify the Problem:
- Explain why this query is causing performance issues.
- Describe what a table scan is and why it’s inefficient in this context.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //search-result.js | |
| //this is a Web Component, NOT a React,Vue or Angular component. | |
| const template = document.createElement('template'); | |
| template.innerHTML = ` | |
| <style> | |
| div { | |
| margin-top: 20px; | |
| color: green; | |
| } |
based on DigitalOcean guide
Create local project
local$ rails new appname -T -d postgresql
local$ rails g scaffold Story title:string body:text
local$ rails db:migrate
install nodejs
sudo apt-get update
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs yarn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {"event": { | |
| "title": "Event title", | |
| "excerpt": "Event excerpt", | |
| "description": "Event description", | |
| "group": "A", | |
| "form": [ | |
| { | |
| "type": "select", | |
| "options": [ | |
| [ |
NewerOlder