Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch error from websocket device status dedupe #6777

Merged
merged 2 commits into from
Jan 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions lib/server/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,13 @@ function init (env, ctx, server) {

// try to find exact match
ctx.store.collection(collection).find(query).toArray(function findResult (err, array) {
if (err || array.length > 0) {
if (err) {
console.error(err);
callback([]);
return;
}

if (array.length > 0) {
console.log(LOG_DEDUP + 'Exact match');
if (callback) {
callback([array[0]]);
Expand Down Expand Up @@ -363,7 +369,14 @@ function init (env, ctx, server) {
// try to find similiar
ctx.store.collection(collection).find(query_similiar).toArray(function findSimiliarResult (err, array) {
// if found similiar just update date. next time it will match exactly
if (err || array.length > 0) {

if (err) {
console.error(err);
callback([]);
return;
}

if (array.length > 0) {
console.log(LOG_DEDUP + 'Found similiar', array[0]);
array[0].created_at = data.data.created_at;
var objId = new ObjectID(array[0]._id);
Expand Down Expand Up @@ -408,14 +421,22 @@ function init (env, ctx, server) {

// try to find exact match
ctx.store.collection(collection).find(queryDev).toArray(function findResult (err, array) {
if (err || array.length > 0) {
console.log(LOG_DEDUP + 'Devicestatus exact match');
if (callback) {
callback([array[0]]);
}
if (err) {
console.error(err);
callback([]);
return;
}

if (array.length > 0) {
console.log(LOG_DEDUP + 'Devicestatus exact match');
if (callback) {
callback([array[0]]);
}
return;
}

});

ctx.store.collection(collection).insert(data.data, function insertResult (err, doc) {
if (err != null && err.message) {
console.log('devicestatus insertion error: ', err.message);
Expand Down