From coder at montx.com Mon Dec 10 04:26:45 2007 From: coder at montx.com (Raimon Fs) Date: Mon, 10 Dec 2007 10:26:45 +0100 Subject: [Rails I18n] transaction when operating in two tables Message-ID: <8c3bf3ae8d45fadffdb03c7519cff9b5@ruby-forum.com> Hello, I'm reading from a table in the database to fetch some path to files to import. I do a loop for each path, and for each .csv file, I update another table. All works perfect, but it takes lot of time, 90 files and aprox. 2.000.000 rows. After adding transactions, the speed has been great, 400% faster. Now, as I see I have to specify the table for wich the transaction occur, where I have to use, the firsst table (where I fetch the path to files) or from the other one ? I update the path file row with a timestamp, rows created/updated/... , so if I problem occurs with some file, I don't want to update their status as done nor having any new data in the other table. for your info: table master => has the path files table dades => has de data database backend => sqlite (only has only one transaction, and not per table, per database) thanks, raimon code: ---------------------------- def import_file_nc8_ajax @txt_to_return = "" @txt_rows_imported = 0 # delete all the rows in Master for nc8 ... @result = Arxiu.find_by_sql('DELETE FROM masters') @txt_to_return += "

Deleted all rows from NC8 table

" @columns = Arxiu.content_columns # id, nc8, nacer @file_paths=Arxiu.find(:all, :conditions => 'kind="nc8"') require 'csv' for arxiu in @file_paths @rows_per_file = 0 begin Master.transaction do CSV.open(arxiu.file_path, "r") do |row| @data_new=Master.new @data_new.nc8 = row[0] @data_new.nacer = row[1] @data_new.save @txt_rows_imported += 1 @rows_per_file += 1 end # CSV.open... do end # transaction rescue end # begin arxiu.update_last=Time.now() arxiu.update_rows = @rows_per_file arxiu.save end @txt_to_return += "

Successfully created " + @txt_rows_imported.to_s + " rows

" @txt_to_return += "

from " + @file_paths.size.to_s + " files

" render(:text => @txt_to_return) end # import_file_nc8_ajax -- Posted via http://www.ruby-forum.com/. From coder at montx.com Mon Dec 10 04:34:53 2007 From: coder at montx.com (Raimon Fs) Date: Mon, 10 Dec 2007 10:34:53 +0100 Subject: [Rails I18n] transaction when operating in two tables In-Reply-To: <8c3bf3ae8d45fadffdb03c7519cff9b5@ruby-forum.com> References: <8c3bf3ae8d45fadffdb03c7519cff9b5@ruby-forum.com> Message-ID: ah, the question ... the question is, where I have to put the begin Master.transaction do and if I have to use the Master table or the Dada table if there are erros, the 99.99% will be in the Dada table, related to the imported data from the .csv file ... thanks, rai -- Posted via http://www.ruby-forum.com/. From fxn at hashref.com Mon Dec 10 04:35:17 2007 From: fxn at hashref.com (Xavier Noria) Date: Mon, 10 Dec 2007 10:35:17 +0100 Subject: [Rails I18n] transaction when operating in two tables In-Reply-To: <8c3bf3ae8d45fadffdb03c7519cff9b5@ruby-forum.com> References: <8c3bf3ae8d45fadffdb03c7519cff9b5@ruby-forum.com> Message-ID: <4C074802-4A29-490D-ACC0-8DFCC025DEFF@hashref.com> Would you please resend this question to rubyonrails-talk? Rails I18n is a mailing list about internationalization. -- fxn On Dec 10, 2007, at 10:26 AM, Raimon Fs wrote: > Hello, > > > I'm reading from a table in the database to fetch some path to files > to > import. > > I do a loop for each path, and for each .csv file, I update another > table. > > All works perfect, but it takes lot of time, 90 files and aprox. > 2.000.000 rows. > > After adding transactions, the speed has been great, 400% faster. > > Now, as I see I have to specify the table for wich the transaction > occur, where I have to use, the firsst table (where I fetch the path > to > files) or from the other one ? > > I update the path file row with a timestamp, rows created/ > updated/... , > so if I problem occurs with some file, I don't want to update their > status as done nor having any new data in the other table. > > for your info: > > table master => has the path files > table dades => has de data > database backend => sqlite (only has only one transaction, and not per > table, per database) > > thanks, > > > raimon > > > > code: > ---------------------------- > > def import_file_nc8_ajax > > @txt_to_return = "" > @txt_rows_imported = 0 > > # delete all the rows in Master for nc8 ... > @result = Arxiu.find_by_sql('DELETE FROM masters') > > @txt_to_return += "

Deleted all rows from NC8 table

" > > @columns = Arxiu.content_columns # id, nc8, nacer > > > @file_paths=Arxiu.find(:all, :conditions => 'kind="nc8"') > > require 'csv' > > > for arxiu in @file_paths > > @rows_per_file = 0 > begin > > Master.transaction do > > CSV.open(arxiu.file_path, "r") do |row| > > @data_new=Master.new > @data_new.nc8 = row[0] > @data_new.nacer = row[1] > @data_new.save > > @txt_rows_imported += 1 > @rows_per_file += 1 > > end # CSV.open... do > > end # transaction > > rescue > > end # begin > > arxiu.update_last=Time.now() > arxiu.update_rows = @rows_per_file > arxiu.save > > > end > > @txt_to_return += "

Successfully created " + > @txt_rows_imported.to_s + " rows

" > @txt_to_return += "

from " + @file_paths.size.to_s + " files >

" > > render(:text => @txt_to_return) > > end # import_file_nc8_ajax > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Railsi18n-discussion mailing list > Railsi18n-discussion at rubyforge.org > http://rubyforge.org/mailman/listinfo/railsi18n-discussion From coder at montx.com Mon Dec 10 04:39:05 2007 From: coder at montx.com (Raimon Fs) Date: Mon, 10 Dec 2007 10:39:05 +0100 Subject: [Rails I18n] transaction when operating in two tables In-Reply-To: <4C074802-4A29-490D-ACC0-8DFCC025DEFF@hashref.com> References: <8c3bf3ae8d45fadffdb03c7519cff9b5@ruby-forum.com> <4C074802-4A29-490D-ACC0-8DFCC025DEFF@hashref.com> Message-ID: Xavier Noria wrote: > Would you please resend this question to rubyonrails-talk? Rails I18n > is a mailing list about internationalization. yes, I'm sorry ... rai -- Posted via http://www.ruby-forum.com/. From spiceee at gmail.com Wed Dec 12 15:36:22 2007 From: spiceee at gmail.com (Fabio Ma) Date: Wed, 12 Dec 2007 21:36:22 +0100 Subject: [Rails I18n] Overriding shipped rails.mo file in gettext 1.10 Message-ID: <310f2b2bbc6276b2cc1edcc7e84962c8@ruby-forum.com> Hey, There are some annoying errors in the shipped pt_BR rails.mo and I'm trying to write my own. Makemo writes my own rails.mo to my locale/pt_BR dir but there's no way it overrides the original rails.mo, not even with init_gettext "rails" in application.rb. Any clues? btw. I can provide whoever does the pt_BR translation with the language errors or maybe become the keeper of the pt_BR translation. I use Gettext in all my Rails projects, anyhow. Tks, Fabio. -- Posted via http://www.ruby-forum.com/. From herman at intermatics.be Tue Dec 18 08:46:45 2007 From: herman at intermatics.be (Herman Jansen) Date: Tue, 18 Dec 2007 14:46:45 +0100 Subject: [Rails I18n] Legacy ISO-8859-1 MSSQL db and UTF8 rails app In-Reply-To: <3e5c8c99d38a903bb47c21afd989cab0@ruby-forum.com> References: <64f457d2222fdd531635bc43aa63b37d@ruby-forum.com> <7776d611a664493070e6451242e96c77@ruby-forum.com> <17818186ab7c9ff95567ad36e208b41c@ruby-forum.com> <3e5c8c99d38a903bb47c21afd989cab0@ruby-forum.com> Message-ID: Julio Damasceno wrote: > Tom Bak wrote: >> I solved my problem with own plugin: >> >> recode_legacy_database :from => "ISO-8859-1", :to => "UTF-8" >> >> Which translates fields in models on read and before write to database. >> >> Cheers, >> Tomasz > > Tom, > > How is the usage of this plugin? I have to run this command manual? When > I have to put this code? > > > Thanks, > > Julio I did it this way : - Unzip the zip-file into you rails vendor/plugins directory - Add the following line to environments.rb ActiveRecord::Base.recode_legacy_database :from=>"ISO-8859-1",:to=>"UTF-8" -- Posted via http://www.ruby-forum.com/. From jozsef.fejes at gmail.com Tue Dec 18 15:15:45 2007 From: jozsef.fejes at gmail.com (Jozsef Fejes) Date: Tue, 18 Dec 2007 21:15:45 +0100 Subject: [Rails I18n] Easy Puzzle Mountain problem In-Reply-To: <612f46cfd17f46b384849a070fea1166@ruby-forum.com> References: <612f46cfd17f46b384849a070fea1166@ruby-forum.com> Message-ID: <4146f2425fe37d9a995a9c019889621c@ruby-forum.com> I solved it: http://jocohp.hu/?o=user_post&id=59&l=1 -- Posted via http://www.ruby-forum.com/.