简体   繁体   English

使用set()方法更新数据的效率怀疑

[英]doubts about efficiency using set() method to update data

i know very well how the set method work. 我非常了解set方法的工作原理。 but I have a doubt about its use to update a node. 但是我对它用于更新节点的使用表示怀疑。 I want to know if when I save an object with a new field (so the same values as before + a new field), is all the fields of the object uploaded again or is only the new field loaded? 我想知道是否在保存带有新字段的对象时(与以前相同的值+一个新字段),是该对象的所有字段都重新上传还是仅加载了新字段?

I see that in the database the unchanged fields are not lit green during writing, this makes me think that 我发现在数据库中未更改的字段在写入过程中未呈绿色亮起,这使我认为

1) all object is sent to the database and after the upload the database simply ignores the fields without modifications. 1)所有对象都发送到数据库,并且在上载之后,数据库仅忽略字段而无需修改。

2) the unchanged fields are not even uploaded into the database (they simply stay in the client) but only new fields are sent. 2)未更改的字段甚至都不会上传到数据库中(它们只是停留在客户端中),而只会发送新字段。

in the second case in a context of large objects there would be a considerable saving of bandwidth 在第二种情况下,在大对象的情况下,将节省大量带宽

const object = {
  name: 'tower10',
  type: 'building',
  rooms: 10
};

await db.ref('object/1').set(object);
object.extra = 'extra content';
object.extra1 = 'extra content 1';
await db.ref('object/1').set(object);

The entire object is sent with every call to set() . 每次调用set()都会发送整个对象。 Children whose values are not change don't count as updates for listeners (as you noticed in the console when their values don't flash). 值未更改的子代不会被视为侦听器的更新(正如您在控制台中看到的那样,当它们的值不闪烁时)。 If you know only certain values are going to change, you cloud only update with those values and not send the entire thing. 如果您仅知道某些值将要更改,那么您只会使用这些值进行更新,而不发送整个信息。 But the object you're showing here is rather small, and I don't think optimizing this small object will matter very much. 但是,您在此处显示的对象很小,我认为优化此小对象并不重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM