Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[留著不一定要解的] async 導致的 state 問題 #9

Open
mark86092 opened this issue Jan 6, 2018 · 0 comments
Open

[留著不一定要解的] async 導致的 state 問題 #9

mark86092 opened this issue Jan 6, 2018 · 0 comments
Labels

Comments

@mark86092
Copy link
Contributor

描述

當用 messenger 連續送出兩張圖時(發兩次對話),會導致 context.state 中,只有一張圖,且打卡完畢,仍然只有一張圖

重現

  1. 首先準備一個 api 可以回傳 db.collection('sessions') 的所有內容
  2. 傳送 不做了,確保 state 被清空 (可以檢查 1 的 api 回傳或用 console.log 看)
"_state": {
  "isWorking":false,
  "startTime":null,
  "endTime":null,
  "location":null,
  "locationTimestamp":null,
  "imgUrls":[]
}
  1. 傳送 做功德,檢查 state 應該是正常的
"_state": {
  "isWorking":true,
  "startTime":"2018-01-06T05:21:58.709Z",
  "endTime":null,
  "location":null,
  "locationTimestamp":null,
  "imgUrls":[]
}
  1. 連續發送兩張圖片 (假裝是上傳打卡照片)

image

  1. 檢查 state
"_state": {
  "isWorking":true,
  "startTime":"2018-01-06T05:21:58.709Z",
  "endTime":null,
  "location":null,
  "locationTimestamp":null,
  "imgUrls":[
    "https://scontent-ort2-1.xx.fbcdn.net/v/t39.1997-6/p100x100/11057103_789355331153381_925532673_n.png?_nc_ad=z-m&_nc_cid=0&oh=c96dd949be1f29576e28f0420be6b66a&oe=5AF1D9C5"
  ]
}

發現 state 沒有忠實儲存兩張圖片,經過多次測試,不一定會存到最後一張

結論

這不是一個嚴重的問題,畢竟在 2~3 秒送多張圖片實在少見

可能的解法

https://github.com/goodjoblife/check-in-bot/blob/master/index.js#L241 這裏

應該把拿到的圖片存進資料庫,而不是 state 中

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant