Commit b1f9ffb3b8ee1307ace49fa2919922f5c47a7b1a

Authored by Volodymyr Babak
1 parent 321d4f1c

Fixes for cases when asset/device deleted but has entity view assigned

@@ -67,3 +67,14 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_cus @@ -67,3 +67,14 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_cus
67 AND id IS NOT NULL 67 AND id IS NOT NULL
68 PRIMARY KEY (tenant_id, customer_id, search_text, id, entity_id) 68 PRIMARY KEY (tenant_id, customer_id, search_text, id, entity_id)
69 WITH CLUSTERING ORDER BY (customer_id DESC, search_text ASC, id DESC); 69 WITH CLUSTERING ORDER BY (customer_id DESC, search_text ASC, id DESC);
  70 +
  71 +CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_entity_id AS
  72 + SELECT *
  73 + from thingsboard.entity_views
  74 + WHERE tenant_id IS NOT NULL
  75 + AND customer_id IS NOT NULL
  76 + AND entity_id IS NOT NULL
  77 + AND search_text IS NOT NULL
  78 + AND id IS NOT NULL
  79 + PRIMARY KEY (tenant_id, entity_id, customer_id, search_text, id)
  80 + WITH CLUSTERING ORDER BY (entity_id DESC, customer_id DESC, search_text ASC, id DESC);
@@ -115,7 +115,7 @@ public class CassandraEntityViewDao extends CassandraAbstractSearchTextDao<Entit @@ -115,7 +115,7 @@ public class CassandraEntityViewDao extends CassandraAbstractSearchTextDao<Entit
115 log.debug("Try to find entity views by tenantId [{}] and entityId [{}]", tenantId, entityId); 115 log.debug("Try to find entity views by tenantId [{}] and entityId [{}]", tenantId, entityId);
116 Select.Where query = select().from(ENTITY_VIEW_BY_TENANT_AND_ENTITY_ID_CF).where(); 116 Select.Where query = select().from(ENTITY_VIEW_BY_TENANT_AND_ENTITY_ID_CF).where();
117 query.and(eq(TENANT_ID_PROPERTY, tenantId)); 117 query.and(eq(TENANT_ID_PROPERTY, tenantId));
118 - query.and(eq(ENTITY_ID_COLUMN, entityId));dr 118 + query.and(eq(ENTITY_ID_COLUMN, entityId));
119 return findListByStatementAsync(query); 119 return findListByStatementAsync(query);
120 } 120 }
121 } 121 }