簡體   English   中英

可以將CSV任務中的Tag Tag轉換為SQLite的標簽?

[英]Rake Tagging from CSV task to much for SQLite?

我有一個rake任務,可通過ID的CSV文件進行搜索。 然后,我查詢數據庫以查看該ID是否存在於數據庫中。 如果存在,則使用act_as_taggable添加標簽。 腳本運行良好,直到到達第一個匹配項並嘗試將標簽寫入我的SQLite DB。 我得到一個數據庫鎖定錯誤。 我想知道我是否達到SQLite的I / O限制,並且需要切換到成熟的MySQL數據庫。

if defined?(Rails) && (Rails.env == 'development')
  Rails.logger = Logger.new(STDOUT)
end

require 'csv'
desc "Tag Voters that early voted from the Secretary of State Website"
task :tag_early => [:environment] do
  file ="db/AllAbsentees.csv"

  CSV.foreach(file, :headers=> true) do |row|
    @voter_id = row[1]
    puts "Working on Row" + row[1]
    @voter = Voter.where(:state_id => @voter_id).first()
    unless @voter.blank?
      @voter.tag_list = "2012_GEN_EARLY_VOTER"
      @voter.save()
      puts "Voter #" + @voter_id + "tagged"
    end
  end
end


    Voter Load (1.2ms)  SELECT "voters".* FROM "voters" WHERE "voters"."state_id" = '00008030' LIMIT 1
  ActsAsTaggableOn::Tag Load (0.2ms)  SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = 11944 AND "taggings"."taggable_type" = 'Voter' AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)
   (0.1ms)  begin transaction
   (0.4ms)  UPDATE "voters" SET "updated_at" = '2012-11-23 00:02:33.438114' WHERE "voters"."id" = 11944
  ActsAsTaggableOn::Tag Load (0.1ms)  SELECT "tags".* FROM "tags" WHERE (lower(name) = '2012_gen_early_voter')
  ActsAsTaggableOn::Tag Load (0.2ms)  SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = 11944 AND "taggings"."taggable_type" = 'Voter' AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)
  ActsAsTaggableOn::Tagging Exists (0.1ms)  SELECT 1 AS one FROM "taggings" WHERE ("taggings"."tag_id" = 19 AND "taggings"."taggable_type" = 'Voter' AND "taggings"."taggable_id" = 11944 AND "taggings"."context" = 'tags' AND "taggings"."tagger_id" IS NULL AND "taggings"."tagger_type" IS NULL) LIMIT 1
  SQL (1.4ms)  INSERT INTO "taggings" ("context", "created_at", "tag_id", "taggable_id", "taggable_type", "tagger_id", "tagger_type") VALUES (?, ?, ?, ?, ?, ?, ?)  [["context", "tags"], ["created_at", Fri, 23 Nov 2012 00:02:33 UTC +00:00], ["tag_id", 19], ["taggable_id", 11944], ["taggable_type", "Voter"], ["tagger_id", nil], ["tagger_type", nil]]
   (5053.1ms)  commit transaction
SQLite3::BusyException: database is locked: commit transaction
   (99.7ms)  rollback transaction
rake aborted!
SQLite3::BusyException: database is locked: commit transaction

SQLite沒有太多的並發性。 要將事務寫入數據庫,必須沒有其他讀取或寫入連接。

確保沒有其他程序同時在讀取或寫入數據庫,並且您自己程序中的所有數據庫訪問均使用相同的數據庫連接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM