SteemJiang发布上的小问题 by lemooljiang

View this thread on steempeak.com
· @lemooljiang · (edited)
$5.79
SteemJiang发布上的小问题
![steemjiang.jpg](https://i.loli.net/2019/11/17/7P943k5rebDV1zX.jpg)

SteemJiang在发布时会出现一个文章时间不同步的问题,如下图所示:

![steemjiang6.jpg](https://i.loli.net/2019/11/30/SOcUhxiq8N4nwGW.jpg)

如上所示,虽是同一篇文章,但发布的时间却是相差几秒,在SteemJiang上就会被判断为两篇文章!

这是什么原因造成的呢? 找想了下,发现是**文章同步到Steem上时的延时造成的!** 

SteemJiang上发布文章的机制是:文章先存储在前端数据库,同时同步到Steem上。问题就出在Steem上是要花费大约3秒的时间,因此会造成一篇文章的创建时间不一致!

**解决的办法就是做一次去重,以文章的permlink做为唯一的标识即可!**

部分代码如下:
```js
//同步文章
//取得最新文章的时间标记
let latestPostFlag = posts[0].created

let permlinkList = []
posts.forEach(item => {
    permlinkList.push(item.permlink)
})

//从steem上获取最新文章
let author = _this.$store.state.username
let beforeDate = new Date().toISOString().split('.')[0]
let newposts = []
let startPermlink = null
while(true){
    let result = await _this.steem.api.getDiscussionsByAuthorBeforeDateAsync(author, startPermlink, beforeDate, 10)
    // console.log(655,result)
    if (latestPostFlag < result[0].created && permlinkList.indexOf(result[0].permlink) === -1 ) {
    //有新文章并且不是重复的文章
    result.forEach(post => {
        if (post.permlink !== startPermlink && permlinkList.indexOf(post.permlink) === -1 ) {
        newposts.push(post)
        }
    })
    //取到最后一篇文章的Permlink,做为下一次查询的起始点
    startPermlink = result[result.length - 1].permlink
    //如果最后一篇文章也是新文章则继续,否则终止while
    if(latestPostFlag > result[result.length - 1].created){
        console.log(233, '没有更新的文章')
        break
    }
    }else{
    // console.log(133, '没有新文章')
    break
    }
}
if(newposts.length > 0){
    await  _this.savePosts(db, newposts)
    console.log(544, '添加新文章成功!')
    let posts2 = await _this.getAllPosts(db)
    _this.$store.commit('savePosts', posts2.reverse())
}
```

👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
post_id82,150,403
authorlemooljiang
permlink9yyv2
categorysteemjiang
json_metadata{"tags":["steemjiang","cn","network-institute","steemjs","steemdev"],"app":"steemit\/1.0","format":"markdown"}
created2019-11-30 15:42:45
last_update2019-11-30 15:43:45
depth0
children3
net_rshares20,999,556,432,292
last_payout2019-12-07 15:42:45
cashout_time1969-12-31 23:59:59
total_payout_value2.933 SBD
curator_payout_value2.861 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length1,675
author_reputation263,700,595,848,611
root_titleSteemJiang发布上的小问题
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (42)
@yellowbird ·
6666

Posted using [Partiko Android](https://partiko.app/referral/yellowbird)
properties (22)
post_id82,160,737
authoryellowbird
permlinkyellowbird-re-lemooljiang-9yyv2-20191130t233518757z
categorysteemjiang
json_metadata{"app":"partiko","client":"android"}
created2019-11-30 23:35:18
last_update2019-11-30 23:35:18
depth1
children0
net_rshares0
last_payout2019-12-07 23:35:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length77
author_reputation68,654,129,782,245
root_titleSteemJiang发布上的小问题
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@wanglizhuifeng ·
当你在steemit上发帖或评论获得SP的时候,已经过去4天左右了,为什么这些SP还没有添加到你的钱包里?
properties (22)
post_id82,210,613
authorwanglizhuifeng
permlinkq1vrfh
categorysteemjiang
json_metadata{"app":"steemit\/0.1"}
created2019-12-02 10:18:51
last_update2019-12-02 10:18:51
depth1
children1
net_rshares0
last_payout2019-12-09 10:18:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length53
author_reputation4,860,340,175,990
root_titleSteemJiang发布上的小问题
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@lemooljiang ·
$0.15
steem是七天结算的,也就是说发贴七天后才会得到sp!
👍  
properties (23)
post_id82,211,336
authorlemooljiang
permlinkq1vt1g
categorysteemjiang
json_metadata{"app":"steemit\/0.1"}
created2019-12-02 10:56:03
last_update2019-12-02 10:56:03
depth2
children0
net_rshares824,522,734,606
last_payout2019-12-09 10:56:03
cashout_time1969-12-31 23:59:59
total_payout_value0.073 SBD
curator_payout_value0.073 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length28
author_reputation263,700,595,848,611
root_titleSteemJiang发布上的小问题
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)