Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
3c37c2d0
W
wechaty
项目概览
.Veneno.
/
wechaty
与 Fork 源项目一致
Fork自
wechaty / wechaty
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3c37c2d0
编写于
6月 15, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove dirty param. use XXXDirty() to explict expire cache instead
上级
cb08e41e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
44 addition
and
83 deletion
+44
-83
src/puppet/puppet.ts
src/puppet/puppet.ts
+44
-83
未找到文件。
src/puppet/puppet.ts
浏览文件 @
3c37c2d0
...
...
@@ -471,28 +471,23 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public
async
contactPayload
(
contactId
:
string
,
dirty
=
false
,
):
Promise
<
ContactPayload
>
{
// log.silly('Puppet', 'contactPayload(id=%s
, dirty=%s) @ %s', contactId, dirty
, this)
// log.silly('Puppet', 'contactPayload(id=%s
) @ %s', contactId
, this)
if
(
!
contactId
)
{
throw
new
Error
(
'
no id
'
)
}
if
(
dirty
)
{
await
this
.
contactPayloadDirty
(
contactId
)
}
else
{
const
cachedPayload
=
this
.
contactPayloadCache
(
contactId
)
if
(
cachedPayload
)
{
return
cachedPayload
}
/**
* 1. Try to get from cache first
*/
const
cachedPayload
=
this
.
contactPayloadCache
(
contactId
)
if
(
cachedPayload
)
{
return
cachedPayload
}
/**
* Cache not found
*
2.
Cache not found
*/
const
rawPayload
=
await
this
.
contactRawPayload
(
contactId
)
const
payload
=
await
this
.
contactRawPayloadParser
(
rawPayload
)
...
...
@@ -537,28 +532,23 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public
async
friendshipPayload
(
friendshipId
:
string
,
dirty
=
false
,
):
Promise
<
FriendshipPayload
>
{
log
.
verbose
(
'
Puppet
'
,
'
friendshipPayload(
id=%s, dirty=%s)
'
,
friendshipId
,
dirty
)
log
.
verbose
(
'
Puppet
'
,
'
friendshipPayload(
%s)
'
,
friendshipId
)
if
(
!
friendshipId
)
{
throw
new
Error
(
'
no id
'
)
}
if
(
dirty
)
{
await
this
.
friendshipPayloadDirty
(
friendshipId
)
}
else
{
const
cachedPayload
=
this
.
friendshipPayloadCache
(
friendshipId
)
if
(
cachedPayload
)
{
return
cachedPayload
}
/**
* 1. Try to get from cache first
*/
const
cachedPayload
=
this
.
friendshipPayloadCache
(
friendshipId
)
if
(
cachedPayload
)
{
return
cachedPayload
}
/**
* Cache not found
*
2.
Cache not found
*/
const
rawPayload
=
await
this
.
friendshipRawPayload
(
friendshipId
)
const
payload
=
await
this
.
friendshipRawPayloadParser
(
rawPayload
)
...
...
@@ -604,28 +594,23 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public
async
messagePayload
(
messageId
:
string
,
dirty
=
false
,
):
Promise
<
MessagePayload
>
{
log
.
verbose
(
'
Puppet
'
,
'
messagePayload(
id=%s, dirty=%s)
'
,
messageId
,
dirty
)
log
.
verbose
(
'
Puppet
'
,
'
messagePayload(
%s)
'
,
messageId
)
if
(
!
messageId
)
{
throw
new
Error
(
'
no id
'
)
}
if
(
dirty
)
{
await
this
.
messagePayloadDirty
(
messageId
)
}
else
{
const
cachedPayload
=
this
.
messagePayloadCache
(
messageId
)
if
(
cachedPayload
)
{
return
cachedPayload
}
/**
* 1. Try to get from cache first
*/
const
cachedPayload
=
this
.
messagePayloadCache
(
messageId
)
if
(
cachedPayload
)
{
return
cachedPayload
}
/**
* Cache not found
*
2.
Cache not found
*/
const
rawPayload
=
await
this
.
messageRawPayload
(
messageId
)
const
payload
=
await
this
.
messageRawPayloadParser
(
rawPayload
)
...
...
@@ -822,28 +807,23 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public
async
roomPayload
(
roomId
:
string
,
dirty
=
false
,
):
Promise
<
RoomPayload
>
{
log
.
verbose
(
'
Puppet
'
,
'
roomPayload(
id=%s, dirty=%s)
'
,
roomId
,
dirty
)
log
.
verbose
(
'
Puppet
'
,
'
roomPayload(
%s%s)
'
,
roomId
)
if
(
!
roomId
)
{
throw
new
Error
(
'
no id
'
)
}
if
(
dirty
)
{
await
this
.
roomPayloadDirty
(
roomId
)
}
else
{
const
cachedPayload
=
this
.
roomPayloadCache
(
roomId
)
if
(
cachedPayload
)
{
return
cachedPayload
}
/**
* 1. Try to get from cache first
*/
const
cachedPayload
=
this
.
roomPayloadCache
(
roomId
)
if
(
cachedPayload
)
{
return
cachedPayload
}
/**
* Cache not found
*
2.
Cache not found
*/
const
rawPayload
=
await
this
.
roomRawPayload
(
roomId
)
const
payload
=
await
this
.
roomRawPayloadParser
(
rawPayload
)
...
...
@@ -861,25 +841,6 @@ export abstract class Puppet extends EventEmitter implements Sayable {
return
contactId
+
'
@@@
'
+
roomId
}
public
roomMemberPayloadCache
(
roomId
:
string
,
contactId
:
string
):
undefined
|
RoomMemberPayload
{
log
.
silly
(
'
Puppet
'
,
'
roomMemberPayloadCache(id=%s) @ %s
'
,
roomId
,
this
)
if
(
!
roomId
||
!
contactId
)
{
throw
new
Error
(
'
no id
'
)
}
const
cacheKey
=
this
.
cacheKeyRoomMember
(
roomId
,
contactId
)
const
cachedPayload
=
this
.
cacheRoomMemberPayload
.
get
(
cacheKey
)
if
(
cachedPayload
)
{
// log.silly('Puppet', 'roomMemberPayloadCache(%s) cache HIT', roomId)
}
else
{
log
.
silly
(
'
Puppet
'
,
'
roomMemberPayloadCache(%s) cache MISS
'
,
roomId
)
}
return
cachedPayload
}
protected
async
roomMemberPayloadDirty
(
roomId
:
string
):
Promise
<
void
>
{
log
.
verbose
(
'
Puppet
'
,
'
roomMemberPayloadDirty(%s)
'
,
roomId
)
...
...
@@ -895,28 +856,28 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public
async
roomMemberPayload
(
roomId
:
string
,
contactId
:
string
,
dirty
=
false
,
):
Promise
<
RoomMemberPayload
>
{
log
.
verbose
(
'
Puppet
'
,
'
roomMemberPayload(roomId=%s, contactId=%s dirty=%s)
'
,
roomId
,
contactId
,
dirty
)
log
.
verbose
(
'
Puppet
'
,
'
roomMemberPayload(roomId=%s, contactId=%s)
'
,
roomId
,
contactId
,
)
if
(
!
roomId
||
!
contactId
)
{
throw
new
Error
(
'
no id
'
)
}
const
cacheKey
=
this
.
cacheKeyRoomMember
(
roomId
,
contactId
)
if
(
dirty
)
{
await
this
.
roomMemberPayloadDirty
(
roomId
)
}
else
{
const
cachedPayload
=
this
.
roomMemberPayloadCache
(
roomId
,
contactId
)
/**
* 1. Try to get from cache
*/
const
cacheKey
=
this
.
cacheKeyRoomMember
(
roomId
,
contactId
)
const
cachedPayload
=
this
.
cacheRoomMemberPayload
.
get
(
cacheKey
)
if
(
cachedPayload
)
{
return
cachedPayload
}
if
(
cachedPayload
)
{
return
cachedPayload
}
/**
* Cache not found
*
2.
Cache not found
*/
const
rawPayload
=
await
this
.
roomMemberRawPayload
(
roomId
,
contactId
)
const
payload
=
await
this
.
roomMemberRawPayloadParser
(
rawPayload
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录