fix(communties): Catch `RequestCommunityInfo`exceptions. Remove diplications. (#10631)

This commit is contained in:
Igor Sirotin 2023-05-11 13:46:54 +03:00 committed by GitHub
parent a57c0b414b
commit dc0e0e6e2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 18 deletions

View File

@ -8,11 +8,8 @@ const asyncLoadCommunitiesDataTask: Task = proc(argEncoded: string) {.gcsafe, ni
let arg = decode[AsyncLoadCommunitiesDataTaskArg](argEncoded)
try:
let responseTags = status_go.getCommunityTags()
let responseCommunities = status_go.getAllCommunities()
let responseSettings = status_go.getCommunitiesSettings()
let responseMyPendingRequestsToJoin = status_go.myPendingRequestsToJoin()
arg.finish(%* {
@ -34,9 +31,20 @@ type
const asyncRequestCommunityInfoTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncRequestCommunityInfoTaskArg](argEncoded)
let response = status_go.requestCommunityInfo(arg.communityId)
let tpl: tuple[communityId: string, response: RpcResponse[JsonNode], importing: bool] = (arg.communityId, response, arg.importing)
arg.finish(tpl)
try:
let response = status_go.requestCommunityInfo(arg.communityId)
arg.finish(%* {
"communityId": arg.communityId,
"importing": arg.importing,
"response": response,
"error": "",
})
except Exception as e:
arg.finish(%* {
"communityId": arg.communityId,
"importing": arg.importing,
"error": e.msg,
})
type
AsyncLoadCuratedCommunitiesTaskArg = ref object of QObjectTaskArg

View File

@ -181,6 +181,7 @@ QtObject:
communities: Table[string, CommunityDto] # [community_id, CommunityDto]
myCommunityRequests*: seq[CommunityMembershipRequestDto]
historyArchiveDownloadTaskCommunityIds*: HashSet[string]
requestedCommunityIds*: HashSet[string]
# Forward declaration
proc asyncLoadCuratedCommunities*(self: Service)
@ -215,6 +216,7 @@ QtObject:
result.communities = initTable[string, CommunityDto]()
result.myCommunityRequests = @[]
result.historyArchiveDownloadTaskCommunityIds = initHashSet[string]()
result.requestedCommunityIds = initHashSet[string]()
proc getFilteredJoinedCommunities(self: Service): Table[string, CommunityDto] =
result = initTable[string, CommunityDto]()
@ -1336,9 +1338,11 @@ QtObject:
return
var community = rpcResponseObj{"response"}{"result"}.toCommunityDto()
let requestedCommunityId = rpcResponseObj{"communityId"}.getStr()
self.requestedCommunityIds.excl(requestedCommunityId)
if community.id == "":
community.id = rpcResponseObj{"response"}{"communityId"}.getStr()
community.id = requestedCommunityId
self.events.emit(SIGNAL_COMMUNITY_LOAD_DATA_FAILED, CommunityArgs(community: community, error: "Couldn't find community info"))
return
@ -1425,17 +1429,20 @@ QtObject:
proc requestCommunityInfo*(self: Service, communityId: string, importing = false) =
try:
let arg = AsyncRequestCommunityInfoTaskArg(
tptr: cast[ByteAddress](asyncRequestCommunityInfoTask),
vptr: cast[ByteAddress](self.vptr),
slot: "asyncCommunityInfoLoaded",
communityId: communityId,
importing: importing
)
self.threadpool.start(arg)
except Exception as e:
error "Error requesting community info", msg = e.msg, communityId
if communityId in self.requestedCommunityIds:
info "requestCommunityInfo: skipping as already requested", communityId
return
self.requestedCommunityIds.incl(communityId)
let arg = AsyncRequestCommunityInfoTaskArg(
tptr: cast[ByteAddress](asyncRequestCommunityInfoTask),
vptr: cast[ByteAddress](self.vptr),
slot: "asyncCommunityInfoLoaded",
communityId: communityId,
importing: importing
)
self.threadpool.start(arg)
proc importCommunity*(self: Service, communityKey: string) =
try: