Ernesto Gimeno

Joined

3,980 Experience
31 Lessons Completed
1 Question Solved

Activity

Posted in User Onboarding Progress Bar Discussion

Great Chris, love this common features series :)

Posted in Rails Application Templates Discussion

I had to define the source paths

def source_paths
  [File.expand_path(File.dirname(__FILE__))]
end

Posted in Rails Application Templates Discussion

I'm trying to create my own template using jumpstart as a guide but the command "directory" is not copying the files from my source directory.

I'm working in local in a folder called templates that contains the file template.rb and also a subfolder with config/initializers/better_errors.rb

I'm doing as in jumpstart:

def copy_initializers
  directory "config/initializers", force: true
end

But the file better_errors.rb is not being copied in the Rails folder. The console log that I get is as follows:

 exist    config/initializers
   identical    config/initializers/application_controller_renderer.rb
   identical    config/initializers/assets.rb
   identical    config/initializers/backtrace_silencers.rb
   identical    config/initializers/cookies_serializer.rb
      create    config/initializers/cors.rb
   identical    config/initializers/filter_parameter_logging.rb
   identical    config/initializers/inflections.rb
   identical    config/initializers/mime_types.rb
      create    config/initializers/new_framework_defaults_5_1.rb
   identical    config/initializers/wrap_parameters.rb

Posted in How to Add Pagination with Pagy Discussion

I found this gem a couple of months ago and I don't see myself going back to kaminari, really good work!

I managed to get  valid YML, translated it,  but the name of the months remains in english.

EDIT. In this issue they talk about it, tried what the last comment says, still no luck. 

https://github.com/basecamp/local_time/pull/53

I tried to copy the keys in locales/en.yml but I get this syntax error:

EDIT. Checking with YAMLLint, looks like the spaces between : and [ are not allowed.

I18n::InvalidLocaleData at /orderscan not load translations from /vagrant/src/pascual-apps/config/locales/en.yml: #<Psych::SyntaxError: (/vagrant/src/pascual-apps/config/locales/en.yml): did not find expected ',' or ']' while parsing a flow sequence at line 34 column 17>

Line 34 is the one for dayNames:

en:
date:
dayNames: [
"Sunday"
"Monday"
"Tuesday"
"Wednesday"
"Thursday"
"Friday"
"Saturday"
]
abbrDayNames: [
"Sun"
"Mon"
"Tue"
"Wed"
"Thu"
"Fri"
"Sat"
]
...

I don't think so, that's the reason for my confusion.

They point to this i18n.coffee file in their docs which contains the default english translations:

https://github.com/basecamp/local_time/blob/master/lib/assets/javascripts/src/local-time/config/i18n.coffee
EDIT. Finally solved, I pasted the keys from I18n.coffee into application.js like that:

LocalTime.config.i18n["es"] = {
    date: {
      dayNames: [
        "Domingo",
        "Lunes",
        "Martes",
        "MiƩrcoles",
        "Jueves",
        "Viernes",
        "Sabado"
      ],
      abbrDayNames: ["Dom", "Lun", "Mar", "Mie", "Ju", "Vie", "Sab"],
.
.
.

then in the same file i placed `LocalTime.config.locale = "es";`
-----------

Hi,

I want to use this gem, which was part of an old episode, but I need to translate the string literals to spanish  in order to use it in my application.

According to their docs, you can just manipulate this file (i18n.coffee) that contains the english defaults, which I did since it looks the easiest way to do it:

The problem is, I don't know where to place this file to get the translated strings loaded, the texts remain as per default. I have modified locales yml files in the past to translate other gems such as devise, but I don't know hot to deal with that.

I have tried in several paths such as:

app/assets/config/i18n.coffee

app/assets/javascripts/src/local-time/config/i18n.coffee

The answer must be pretty obvious but I can't find it :(, any help would be appreciated.

Posted in Improve performance of simple searching method

Hi, today I have been trying something different, so I decided to give a try to pg_search, using the trigram extension which I read is more performant for ILIKE %% type of conditions, but it is being like 3-4 times slower than the previous snippet from the post above. I have only tried in local.

Any ideas about what can be happening? I would appreciate any help.

class PartMaster < ApplicationRecord
  include PgSearch

  has_many :part_variants, foreign_key: 'sap_cod', primary_key: 'sap_cod'
  has_many :locations, foreign_key: 'sap_cod', primary_key: 'sap_cod'

  scope :con_stock, -> { where("stock > 0") }
  scope :planta, -> (planta) { where planta_cod: planta}

  pg_search_scope :search_keywords,
                against: {sap_cod: :A, descripcion_maestro: :B, fabricante: :C, ref_fabricante: :D},
                ignoring: :accents,
                :associated_against => {
                    part_variants: [:fabricante_prov, :ref_prov]
                },
                using: {
                  tsearch: {dictionary: 'spanish'},
                  trigram: {dictionary: "english"}
                }

  def self.search(params)
    recordset = PartMaster.joins(:part_variants).all
    recordset = recordset.con_stock if params[:stock].present?
    recordset = recordset.planta(params[:planta]) if params[:planta].present?
    recordset = recordset.search_keywords(params[:search])
    recordset
  end

end




Posted in Improve performance of simple searching method

Hi,

I have been building an app these days. The functionality is nothing fancy at all, I have to connect to a client's SOAP webservice, fetch some data, save it into my pg database and build a search functionality based on this data.

The search has to be performed on two tables,  both combined are like 80K rows. It needs to look for every word in the input text in several fields from these two tables, which have a classical assocation one to many. 

Previous to get my hands dirty I was looking at the choices I had to get the functionality done (ransack, searchkick, scoped_search etc), but I ended up trying first just vanilla Active Record and I was very surprised to find that I could achieve the functionality way easier than I thought and with an acceptable response time, about to 400ms active record time for the most expensive  queries in local.

So the problem is, the performance of this app in Heroku is way worse than in local (I'm developing using  a vagrant box btw). On average, queries take 2-3 times longer than in local, so the user experience goes from acceptable to poor. I was wondering If someone could help to improve my query. I'm also worried about how the background job that fetchs the data is also way les performant than in local and about some issues with the memory, but that's a different story though.

The relevant snippets are these:

`part_master.rb` where the search method is implemented:

class PartMaster < ApplicationRecord
  has_many :part_variants, foreign_key: 'sap_cod', primary_key: 'sap_cod'
  has_many :locations, foreign_key: 'sap_cod', primary_key: 'sap_cod'

  scope :con_stock, -> { where("stock > 0") }
  scope :planta, -> (planta) { where planta_cod: planta}

  def self.search(params)
    recordset = PartMaster.joins(:part_variants).all
    recordset = recordset.con_stock if params[:stock].present?
    recordset = recordset.planta(params[:planta]) if params[:planta].present?
    recordset = search_keywords(params[:search], recordset)
    recordset
  end

  private 

  def self.search_keywords(query, recordset)
    keywords = query.to_s.strip.split
    if query
      keywords.each do |keyword|
        recordset = recordset.where('part_masters.sap_cod ILIKE :q OR unaccent(descripcion_maestro) ILIKE unaccent(:q)
                                     OR fabricante ILIKE :q OR ref_fabricante ILIKE :q 
                                     OR fabricante_prov ILIKE :q OR ref_prov ILIKE :q', q: "%#{keyword}%")
      end
      recordset.distinct.order(:sap_cod)
    end
  end
end

And this is the call to the method from the controller:

  def index
    parts = params[:search].present? ? PartMaster.search(params) : PartMaster.none
    @parts = parts.page(params[:page]).per(50)
  end

I have an index in every searchable field. 

Thank you in advance!

Posted in Improving In-App Notifications Discussion

Great episode Chris, newbie question here.

I adapted it to the app I'm currently working on, and works like a charm in localhost but in production (Heroku) the mark_as_read method gets only triggered after I do a hard refresh of the browser, otherwise the notifications remain as read: false even if I hit the link a hundred times. Might be an issue with turbolinks?

I read something in the slack channel about how the javascript should be running on turbolinks:load event instead of the dom content ready, but I'm not sure about how to do this. I could try just to remove turbolinks from the app but I would be losing a lot of speed. Any thoughts?