hasyrails / calendar-vue-original

0 stars 0 forks source link

SQLite3::BusyException: database is locked #297

Open hasyrails opened 3 years ago

hasyrails commented 3 years ago

現状

card.start / card.deadline を 1ヶ月期間で登録すると、2日分しか登録できない?

リロード処理を無くしてもダメ

予定を登録するメソッド

async createScheduleAction({ commit }, card){
      const scheduleDate = {
        start: new Date(card.start),
        deadline: new Date(card.deadline),
      }      
      var currentDate = scheduleDate.start
      const startDate = scheduleDate.start
      var stopDate = scheduleDate.deadline

      for(let i =1;  i <=Math.floor((new Date(stopDate).getTime()-new Date(startDate).getTime())/86400000)+1; i++) {
        var schedule = {
          body: card.body,
          color: card.color,
          start: scheduleDate.start,
          deadline: scheduleDate.deadline,
          date: currentDate,
          date_year: new Date(currentDate).getFullYear(),
          date_month: new Date(currentDate).getMonth()+1,
          date_day: new Date(currentDate).getDate(),
          card_id: card.id,
          user_id: card.user_id
        }

        await axios.post('api/schedules', schedule)
          .then(res => {
            commit('createSchedule', res.data)
          })
          .catch(error => console.log(error.response));

        currentDate = new Date(currentDate).setDate(new Date(currentDate).getDate() + 1);
        schedule.date = currentDate
      }

      await axios.patch('api/cards/'+card.id, card)
          .then(res => {
            commit('cards/updateCard', res.data)
          })
          .catch(error => console.log(error.response));
    },
hasyrails commented 3 years ago

POSTリクエストのawaitを無くしてみた

 - await axios.post('api/schedules', schedule)
 + axios.post('api/schedules', schedule)

sqliteでエラー

Schedule Create (102701.3ms)  INSERT INTO "schedules" ("body", "start", "deadline", "date_year", "date_month", "date_day", "card_id", "user_id", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  [["body", "kkkkkk"], ["start", "2020-11-01"], ["deadline", "2020-11-30"], ["date_year", 2020], ["date_month", 11], ["date_day", 11], ["card_id", 34], ["user_id", 6], ["created_at", "2020-11-01 22:21:26.742717"], ["updated_at", "2020-11-01 22:21:26.742717"]]
22:23:09 web.1       | Processing by HomeController#index as HTML
22:23:09 web.1       |    (1.8ms)  commit transaction
22:23:09 web.1       |   ↳ app/controllers/api/schedules_controller.rb:19
22:23:09 web.1       |   Parameters: {"path"=>"schedules"}
22:23:09 web.1       |   ↳ app/controllers/api/schedules_controller.rb:19
22:23:09 web.1       |    (0.2ms)  rollback transaction
22:23:09 web.1       | Completed 200 OK in 102750ms (Views: 0.5ms | ActiveRecord: 4.7ms)
22:23:09 web.1       | 
22:23:09 web.1       | 
22:23:09 web.1       |   ↳ app/controllers/api/schedules_controller.rb:19
22:23:09 web.1       | Completed 500 Internal Server Error in 102783ms (ActiveRecord: 102701.8ms)
22:23:09 web.1       | 
22:23:09 web.1       | 
22:23:09 web.1       |   
22:23:09 web.1       | ActiveRecord::StatementInvalid (SQLite3::BusyException: database is locked: INSERT INTO "schedules" ("body", "start", "deadline", "date_year", "date_month", "date_day", "card_id", "user_id", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)):
hasyrails commented 3 years ago

データベースを変える必要がある??

ActiveRecord::StatementInvalid (SQLite3::BusyException: database is locked:

SQLite3::BusyException / StackOverFlow

hasyrails commented 3 years ago

MySQLへの移行を検討する必要あり

業務用Webアプリ(RoR/sqlite3)の保守・運用に関する相談

hasyrails commented 3 years ago

ref #298 MySQLに変更することで改善