Skip to content

Commit d2bc4ab

Browse files
authored
Fix heavy bogus database writes (dresden-elektronik#7281)
Currently there are some database writes after startup and closing deCONZ which are very heavy and just write already present entries. The change prevents these writes. Also fixes trying to change a valid sensor uniqueid to one with invalid endpoint 0xFF.
1 parent a908949 commit d2bc4ab

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

database.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4210,7 +4210,7 @@ static int sqliteLoadAllSensorsCallback(void *user, int ncols, char **colval , c
42104210
}
42114211
}
42124212

4213-
if (extAddr != 0)
4213+
if (extAddr != 0 && endpoint != 0xFF)
42144214
{
42154215
const QString uid = generateUniqueId(extAddr, endpoint, clusterId);
42164216

de_web_plugin.cpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -2583,10 +2583,9 @@ void DeRestPluginPrivate::addLightNode(const deCONZ::Node *node)
25832583
{ }
25842584
else if (node->nodeDescriptor().manufacturerCode() == VENDOR_NONE || (node->nodeDescriptor().manufacturerCode() == VENDOR_EMBER))
25852585
{
2586+
// TODO(mpi): this needs to go in favor of DDF
25862587
if (manufacturer.isEmpty())
25872588
{
2588-
DBG_Printf(DBG_INFO_L2, "Tuya debug 7 : Missing manufacture name for 0x%016llx\n", node->address().ext());
2589-
25902589
//searching in DB
25912590
openDb();
25922591
manufacturer = loadDataForLightNodeFromDb(generateUniqueId(node->address().ext(),0,0));
@@ -2599,18 +2598,14 @@ void DeRestPluginPrivate::addLightNode(const deCONZ::Node *node)
25992598
if (sensor && !sensor->manufacturer().isEmpty())
26002599
{
26012600
manufacturer = sensor->manufacturer();
2601+
lightNode.setNeedSaveDatabase(true);
26022602
}
26032603
}
26042604

2605-
if (manufacturer.isEmpty())
2606-
{
2607-
DBG_Printf(DBG_INFO_L2, "Tuya debug 7 : Missing manufacture name, till missing in DB.\n");
2608-
}
2609-
}
2610-
if (!manufacturer.isEmpty())
2611-
{
2612-
lightNode.setManufacturerName(manufacturer);
2613-
lightNode.setNeedSaveDatabase(true);
2605+
if (!manufacturer.isEmpty())
2606+
{
2607+
lightNode.setManufacturerName(manufacturer);
2608+
}
26142609
}
26152610
}
26162611

@@ -15886,6 +15881,9 @@ void DeRestPlugin::appAboutToQuit()
1588615881
d->openDb();
1588715882
d->saveDb();
1588815883

15884+
// TODO(mpi): Following is really heavy and already done previously
15885+
// storing items needs to get more explicit with dirty flags
15886+
#if 0
1588915887
for (const auto &dev : d->m_devices)
1589015888
{
1589115889
if (dev->managed())
@@ -15896,6 +15894,7 @@ void DeRestPlugin::appAboutToQuit()
1589615894
}
1589715895
}
1589815896
}
15897+
#endif
1589915898

1590015899
d->ttlDataBaseConnection = 0;
1590115900
d->closeDb();

device_compat.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ static Resource *DEV_InitSensorNodeFromDescription(Device *device, const DeviceD
8686
else
8787
{
8888
sensor.setId(QString::number(getFreeSensorId()));
89+
sensor.setNeedSaveDatabase(true);
8990
}
9091
}
9192

@@ -103,10 +104,10 @@ static Resource *DEV_InitSensorNodeFromDescription(Device *device, const DeviceD
103104
friendlyName = friendlyName.mid(3);
104105
}
105106
sensor.setName(QString("%1 %2").arg(friendlyName, sensor.id()));
107+
sensor.setNeedSaveDatabase(true);
106108
}
107109
}
108110

109-
sensor.setNeedSaveDatabase(true);
110111
sensor.rx();
111112

112113
auto *r = DEV_AddResource(sensor);
@@ -192,6 +193,7 @@ static Resource *DEV_InitLightNodeFromDescription(Device *device, const DeviceDe
192193
else
193194
{
194195
lightNode.setId(QString::number(getFreeLightId()));
196+
lightNode.setNeedSaveDatabase(true);
195197
}
196198
}
197199

@@ -204,6 +206,7 @@ static Resource *DEV_InitLightNodeFromDescription(Device *device, const DeviceDe
204206
else
205207
{
206208
lightNode.setName(QString("%1 %2").arg(lightNode.type(), lightNode.id()));
209+
lightNode.setNeedSaveDatabase(true);
207210
}
208211
}
209212

@@ -242,7 +245,6 @@ static Resource *DEV_InitLightNodeFromDescription(Device *device, const DeviceDe
242245
lightNode.removeItem(RStateSat);
243246
lightNode.removeItem(RStateAlert);
244247

245-
lightNode.setNeedSaveDatabase(true);
246248
lightNode.rx();
247249

248250
auto *r = DEV_AddResource(lightNode);

0 commit comments

Comments
 (0)