Giter VIP home page Giter VIP logo

Comments (18)

DAddYE avatar DAddYE commented on July 19, 2024

Yep, are u using it with padrino?

The query problem is due to a reloading issue.

I've also have a problem with the connection not closed, but also doesn't depend from MiniRecord but from an api change https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L418

I think (but I need to check) this will occurs only with some webservers like thin or so.

from mini_record.

cj avatar cj commented on July 19, 2024

Yes, I'm using padrino.... It does it in Webrick, thin and apache + passenger. Is there anyway to fix the issue(s)? They seem like pretty big ones......

from mini_record.

DAddYE avatar DAddYE commented on July 19, 2024

Always running query should solved with a stop/restart of the webserver or touch tmp/restart.txt under passenger.

The connection problem Im unable to reproduce it this because sometimes happens others not.

You have an idea how to reproduce it?

from mini_record.

cj avatar cj commented on July 19, 2024

Always running query should solved with a stop/restart

how do you mean? I've started and stopped the server a bunch of times and it still runs those queries every time.

The connection problem Im unable to reproduce it this because sometimes happens others not.

It happens on every 6 th page load/db connection, so my guess it's to do with :pool => 5, in the ActiveRecord::Base.configurations

10:55 ~/Dropbox/sd/acd/receptionist (master *3)$ padrino start
DEPRECATION WARNING: Yajl's JSON gem compatibility API is going to be removed in 2.0
   INFO - Running any db changes.
  DEBUG -  (46.5ms)  ALTER TABLE `calls` CHANGE `direction` `direction` ENUM('inbound', 'outbound') DEFAULT NULL
  DEBUG -  (22.3ms)  ALTER TABLE `calls` CHANGE `receptionist_id` `receptionist_id` int(11) DEFAULT NULL
  DEBUG -  (15.6ms)  ALTER TABLE `calls` CHANGE `closed` `closed` tinyint(1) DEFAULT 0
  DEBUG -  (33.3ms)  ALTER TABLE `calls` CHANGE `holiday` `holiday` tinyint(1) DEFAULT 0
=> Padrino/0.10.6.c has taken the stage development at http://0.0.0.0:3000
[2012-02-03 10:55:46] INFO  WEBrick 1.3.1
[2012-02-03 10:55:46] INFO  ruby 1.9.3 (2011-10-30) [x86_64-darwin11.2.0]
[2012-02-03 10:55:46] INFO  WEBrick::HTTPServer#start: pid=60370 port=3000
   INFO - Running any db changes.
  DEBUG -  (13.7ms)  ALTER TABLE `calls` CHANGE `direction` `direction` ENUM('inbound', 'outbound') DEFAULT NULL
  DEBUG -  (10.2ms)  ALTER TABLE `calls` CHANGE `receptionist_id` `receptionist_id` int(11) DEFAULT NULL
  DEBUG -  (8.0ms)  ALTER TABLE `calls` CHANGE `closed` `closed` tinyint(1) DEFAULT 0
  DEBUG -  (11.8ms)  ALTER TABLE `calls` CHANGE `holiday` `holiday` tinyint(1) DEFAULT 0
  DEBUG - User Load (3.4ms)  SELECT `users`.* FROM `users` WHERE `users`.`acd_api_uid` = 8345 LIMIT 1
  DEBUG - TEMPLATE (0.0003ms) /dashboard.html
  DEBUG - TEMPLATE (0.0001ms) /layouts/application.html
  DEBUG -      GET (0.2109ms) / - 200 OK
  DEBUG -      GET (0.2897ms) /css/bootstrap/bootstrap.621727.css - 200 OK
   INFO - Running any db changes.
  DEBUG -  (26.1ms)  ALTER TABLE `calls` CHANGE `direction` `direction` ENUM('inbound', 'outbound') DEFAULT NULL
  DEBUG -  (10.9ms)  ALTER TABLE `calls` CHANGE `receptionist_id` `receptionist_id` int(11) DEFAULT NULL
  DEBUG -  (8.9ms)  ALTER TABLE `calls` CHANGE `closed` `closed` tinyint(1) DEFAULT 0
  DEBUG -  (14.7ms)  ALTER TABLE `calls` CHANGE `holiday` `holiday` tinyint(1) DEFAULT 0
  DEBUG - User Load (0.9ms)  SELECT `users`.* FROM `users` WHERE `users`.`acd_api_uid` = 8345 LIMIT 1
  DEBUG - TEMPLATE (0.0003ms) /dashboard.html
  DEBUG - TEMPLATE (0.0001ms) /layouts/application.html
  DEBUG -      GET (0.1360ms) / - 200 OK
  DEBUG -      GET (0.3349ms) /css/bootstrap/bootstrap.621727.css - 200 OK
   INFO - Running any db changes.
  DEBUG -  (21.7ms)  ALTER TABLE `calls` CHANGE `direction` `direction` ENUM('inbound', 'outbound') DEFAULT NULL
  DEBUG -  (11.5ms)  ALTER TABLE `calls` CHANGE `receptionist_id` `receptionist_id` int(11) DEFAULT NULL
  DEBUG -  (9.0ms)  ALTER TABLE `calls` CHANGE `closed` `closed` tinyint(1) DEFAULT 0
  DEBUG -  (13.9ms)  ALTER TABLE `calls` CHANGE `holiday` `holiday` tinyint(1) DEFAULT 0
  DEBUG - User Load (0.4ms)  SELECT `users`.* FROM `users` WHERE `users`.`acd_api_uid` = 8345 LIMIT 1
  DEBUG - TEMPLATE (0.0003ms) /dashboard.html
  DEBUG - TEMPLATE (0.0001ms) /layouts/application.html
  DEBUG -      GET (0.1245ms) / - 200 OK
   INFO - Running any db changes.
  DEBUG -  (14.1ms)  ALTER TABLE `calls` CHANGE `direction` `direction` ENUM('inbound', 'outbound') DEFAULT NULL
  DEBUG -  (9.6ms)  ALTER TABLE `calls` CHANGE `receptionist_id` `receptionist_id` int(11) DEFAULT NULL
  DEBUG -  (13.7ms)  ALTER TABLE `calls` CHANGE `closed` `closed` tinyint(1) DEFAULT 0
  DEBUG -  (17.2ms)  ALTER TABLE `calls` CHANGE `holiday` `holiday` tinyint(1) DEFAULT 0
  DEBUG -      GET (0.4412ms) /css/bootstrap/bootstrap.621727.css - 200 OK
   INFO - Running any db changes.
DEPRECATION WARNING: Database connections will not be closed automatically, please close your
database connection at the end of the thread by calling `close` on your
connection.  For example: ActiveRecord::Base.connection.close
. (called from mon_synchronize at /Users/cj/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211)
DEPRECATION WARNING: Database connections will not be closed automatically, please close your
database connection at the end of the thread by calling `close` on your
connection.  For example: ActiveRecord::Base.connection.close
. (called from mon_synchronize at /Users/cj/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211)
DEPRECATION WARNING: Database connections will not be closed automatically, please close your
database connection at the end of the thread by calling `close` on your
connection.  For example: ActiveRecord::Base.connection.close
. (called from mon_synchronize at /Users/cj/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211)
DEPRECATION WARNING: Database connections will not be closed automatically, please close your
database connection at the end of the thread by calling `close` on your
connection.  For example: ActiveRecord::Base.connection.close
. (called from mon_synchronize at /Users/cj/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211)
  DEBUG -  (19.1ms)  ALTER TABLE `calls` CHANGE `direction` `direction` ENUM('inbound', 'outbound') DEFAULT NULL
  DEBUG -  (19.2ms)  ALTER TABLE `calls` CHANGE `receptionist_id` `receptionist_id` int(11) DEFAULT NULL
  DEBUG -  (19.2ms)  ALTER TABLE `calls` CHANGE `closed` `closed` tinyint(1) DEFAULT 0
  DEBUG -  (11.4ms)  ALTER TABLE `calls` CHANGE `holiday` `holiday` tinyint(1) DEFAULT 0
  DEBUG - User Load (0.5ms)  SELECT `users`.* FROM `users` WHERE `users`.`acd_api_uid` = 8345 LIMIT 1
  DEBUG - TEMPLATE (0.0003ms) /dashboard.html
  DEBUG - TEMPLATE (0.0001ms) /layouts/application.html
  DEBUG -      GET (5.3785ms) / - 200 OK
  DEBUG -      GET (0.3383ms) /css/bootstrap/bootstrap.621727.css - 200 OK


from mini_record.

DAddYE avatar DAddYE commented on July 19, 2024

Problem one should be solved replacing this:

col :closed, :holiday, as: :boolean, default: 0

into:

col :closed, :holiday, as: :boolean, default: false

from mini_record.

DAddYE avatar DAddYE commented on July 19, 2024

So I think once query problem will be solved also connection closed will be.

from mini_record.

cj avatar cj commented on July 19, 2024

Looks like you just need to add ActiveRecord::Base.connection.close to the end of auto_upgrade!

from mini_record.

DAddYE avatar DAddYE commented on July 19, 2024

@cj mmm can be, but be sure to use true or false when the col is :boolean the migration will fail so for that reason will be performed every time.

from mini_record.

cj avatar cj commented on July 19, 2024

Problem one should be solved replacing this:

col :closed, :holiday, as: :boolean, default: 0

into:

col :closed, :holiday, as: :boolean, default: false

Now I'm just left with:


  DEBUG -  (40.4ms)  ALTER TABLE `calls` CHANGE `direction` `direction` ENUM('inbound', 'outbound') DEFAULT NULL
  DEBUG -  (14.9ms)  ALTER TABLE `calls` CHANGE `receptionist_id` `receptionist_id` int(11) DEFAULT NULL

With this schema:

  schema { |t| t.column :direction, "ENUM('inbound', 'outbound')" }
  add_index :direction
  col :receptionist_id, as: :integer, limit: 11, index: true
  col :closed, :holiday, as: :boolean, default: false
  col :to, :from, :sid, :api_version, :status, index: true
  col :start, :end, as: :datetime
  col :duration, as: :integer
  timestamps

from mini_record.

DAddYE avatar DAddYE commented on July 19, 2024

This col :receptionist_id, as: :integer, limit: 11, index: true should be solved removing the limit

col :receptionist_id, as: :integer, index: true

from mini_record.

cj avatar cj commented on July 19, 2024

I need the limit (at the db level) though :)

from mini_record.

DAddYE avatar DAddYE commented on July 19, 2024

If Im not wrong AR add it for you, so is not necessary.

from mini_record.

cj avatar cj commented on July 19, 2024

Surely that is a bug though because if I want to limit a string size or limit an integer to 5 it's still going to happen.... same when using schema

from mini_record.

DAddYE avatar DAddYE commented on July 19, 2024

Perfect! I will add some specs and solve the issue!

from mini_record.

cj avatar cj commented on July 19, 2024

Thank you :)

from mini_record.

DAddYE avatar DAddYE commented on July 19, 2024

After digging a bit into this issue, there is no way to solve it.

When you use :limit => 11 mysql adapter convert it to :limit => 4

class Task < ActiveRecord::Base
   key :priority, :limit => 11
end
# ALTER TABLE `tasks` CHANGE `priority` `priority` int(11)
Task.auto_upgrade!

Now checking:

cols = ActiveRecord::Base.connection.columns('tasks').inject({}) { |hash, col| hash[col.name] = col; hash }

So now if we check the db limit:

cols['priority'].limit

It returns: 4.

This because in MySql Adapter of ActiveRecord we have this:

 case limit
 when 1; 'tinyint'
 when 2; 'smallint'
 when 3; 'mediumint'
 when nil, 4, 11; 'int(11)'  # compatibility with MySQL default
 when 5..8; 'bigint'
 else raise(ActiveRecordError, "No integer type has byte size #{limit}")
 end

Here another problem, I cant remap those values back because are specific for MySql, nor Sqlite or Postgres have this kind of mapping.

So the problem I think is quite small, this happens only when you use integer limit, so If you are using i.e. limit: 11 it's better to translate it directly to limit: 4 since it creates limit: 11.

Thoughts ?

from mini_record.

cj avatar cj commented on July 19, 2024

Is there no way to add some logic to ignore limit 11? Just so that if someone does enter it at least the query won't run every time. Also what about the big issue of schema { |t| t.column :direction, "ENUM('inbound', 'outbound')" } running every page request?

from mini_record.

DAddYE avatar DAddYE commented on July 19, 2024

You haven't any kind of problems if you use any values different than 4 or 11 since both are stored as default.

Check updated test for more info.

This happens only with integers none occurs with string or other types.

For the second problem, make me a pull request (if you have time) with only a failing test.

Thank you man!

from mini_record.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.