Parcourir la source

do not throw error if the content-dir Class is unknown, just log

metmirr il y a 4 ans
Parent
commit
45e2579554

+ 3 - 4
query-node/src/content-directory/entity-helper.ts

@@ -161,7 +161,6 @@ async function createVideo({ db, block, id }: IDBBlockId, p: IVideo): Promise<vo
   video.thumbnailUrl = p.thumbnailURL
   video.version = block
   video.happenedIn = await createBlockOrGetFromDatabase(db, block)
-  console.log(video)
   await db.save<Video>(video)
 }
 
@@ -208,14 +207,14 @@ async function getClassName(
     throw Error(`Can not determine class of the entity`)
   }
 
-  let classId: number
+  let classId: number | undefined
   // Is newly created entity in the same transaction
   if (indexOf !== undefined) {
     classId = createEntityOperations[indexOf].classId
   } else {
     const ce = await db.get(ClassEntity, { where: { id: entityId } })
-    if (ce === undefined) throw Error(`Class not found for the entity: ${entityId}`)
-    classId = ce.classId
+    if (ce === undefined) console.log(`Class not found for the entity: ${entityId}`)
+    classId = ce ? ce.classId : undefined
   }
 
   const c = contentDirectoryClassNamesWithId.find((c) => c.classId === classId)

+ 18 - 4
query-node/src/content-directory/entity.ts

@@ -34,6 +34,7 @@ import {
   updateKnownLicenseEntityPropertyValues,
   updateLanguageEntityPropertyValues,
   updateVideoMediaEncodingEntityPropertyValues,
+  createBlockOrGetFromDatabase,
 } from './entity-helper'
 import {
   CategoryPropertyNamesWithId,
@@ -75,10 +76,16 @@ async function contentDirectory_EntitySchemaSupportAdded(db: DB, event: Substrat
   const entityId = decode.stringIfyEntityId(event)
   const classEntity = await db.get(ClassEntity, { where: { id: entityId } })
 
-  if (classEntity === undefined) throw Error(`Class not found for the EntityId: ${entityId}`)
+  if (classEntity === undefined) {
+    console.log(`Class not found for the EntityId: ${entityId}`)
+    return
+  }
 
   const cls = contentDirectoryClassNamesWithId.find((c) => c.classId === classEntity.classId)
-  if (cls === undefined) throw Error('Not recognized class')
+  if (cls === undefined) {
+    console.log('Not recognized class')
+    return
+  }
 
   const arg: IDBBlockId = { db, block, id: entityId }
 
@@ -148,10 +155,16 @@ async function contentDirectory_EntityRemoved(db: DB, event: SubstrateEvent): Pr
   const where: IWhereCond = { where: { id: entityId } }
 
   const classEntity = await db.get(ClassEntity, where)
-  if (classEntity === undefined) throw Error(`Class not found for the EntityId: ${entityId}`)
+  if (classEntity === undefined) {
+    console.log(`Class not found for the EntityId: ${entityId}`)
+    return
+  }
 
   const cls = contentDirectoryClassNamesWithId.find((c) => c.classId === classEntity.classId)
-  if (cls === undefined) throw Error('Undefined class')
+  if (cls === undefined) {
+    console.log('Undefined class')
+    return
+  }
 
   switch (cls.name) {
     case ContentDirectoryKnownClasses.CHANNEL:
@@ -209,6 +222,7 @@ async function contentDirectory_EntityCreated(db: DB, event: SubstrateEvent): Pr
   classEntity.classId = c.classId
   classEntity.id = c.entityId.toString()
   classEntity.version = event.blockNumber
+  classEntity.happenedIn = await createBlockOrGetFromDatabase(db, event.blockNumber)
   await db.save<ClassEntity>(classEntity)
 }
 

+ 1 - 0
query-node/src/content-directory/mapping.ts

@@ -2,5 +2,6 @@ export {
   contentDirectory_EntitySchemaSupportAdded,
   contentDirectory_EntityRemoved,
   contentDirectory_EntityCreated,
+  contentDirectory_EntityPropertyValuesUpdated,
 } from './entity'
 export { contentDirectory_TransactionCompleted } from './transaction'

+ 10 - 9
query-node/src/content-directory/transaction.ts

@@ -56,11 +56,11 @@ import {
   batchCreateClassEntities,
 } from './entity-helper'
 
-const debug = Debug('mappings:content-directory:TransactionCompleted')
+const debug = Debug('mappings:content-directory')
 
 // eslint-disable-next-line @typescript-eslint/naming-convention
 export async function contentDirectory_TransactionCompleted(db: DB, event: SubstrateEvent): Promise<void> {
-  debug(`Substrate event: ${JSON.stringify(event)}`)
+  debug(`TransactionCompleted event: ${JSON.stringify(event)}`)
 
   const { extrinsic, blockNumber: block } = event
   if (!extrinsic) {
@@ -102,8 +102,6 @@ async function batchAddSchemaSupportToEntity(
 ) {
   // find the related entity ie. Channel, Video etc
   for (const entity of entities) {
-    debug(`Entity: ${JSON.stringify(entity)}`)
-
     const { entityId, indexOf, properties } = entity
 
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -174,7 +172,8 @@ async function batchAddSchemaSupportToEntity(
         break
 
       default:
-        throw new Error(`Unknown class name: ${className}`)
+        console.log(`Unknown class name: ${className}`)
+        break
     }
   }
 }
@@ -187,15 +186,16 @@ async function batchAddSchemaSupportToEntity(
  */
 async function batchUpdatePropertyValue(db: DB, createEntityOperations: ICreateEntityOperation[], entities: IEntity[]) {
   for (const entity of entities) {
-    debug(`Update entity properties values: ${JSON.stringify(entity)}`)
-
     const { entityId, indexOf, properties } = entity
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     const id = entityId ? entityId.toString() : indexOf!.toString()
 
     const where: IWhereCond = { where: { id } }
     const className = await getClassName(db, entity, createEntityOperations)
-    if (className === undefined) throw Error(`Can not update entity properties values. Unknown class name`)
+    if (className === undefined) {
+      console.log(`Can not update entity properties values. Unknown class name`)
+      return
+    }
 
     switch (className) {
       case ContentDirectoryKnownClasses.CHANNEL:
@@ -279,7 +279,8 @@ async function batchUpdatePropertyValue(db: DB, createEntityOperations: ICreateE
         break
 
       default:
-        throw new Error(`Unknown class name: ${className}`)
+        console.log(`Unknown class name: ${className}`)
+        break
     }
   }
 }