apache / openwhisk

Apache OpenWhisk is an open source serverless cloud platform
https://openwhisk.apache.org/
Apache License 2.0
6.56k stars 1.17k forks source link

Fix packages-public view function #5508

Open dorbae opened 2 months ago

dorbae commented 2 months ago

These changes make whisks.v.2.1/packges-public view function to check whether doc.binding is undfined before getting the length of it. It can prevent from CouchDB producing unnecessary logs.

Description

When 'packages-public' view builds the index, you can find these logs.

[info] 2024-09-07T02:25:38.312234Z nonode@nohost <0.1292.0> -------- OS Process #Port<0.8249> Log :: function raised exception (new TypeError("doc.binding is not an object", "undefined", 3)) with doc._id whisk.system/user25868/TEST

I modified 'isPublicPackage' function. I believe that use 'Falsy' because there's no need to check the length of doc.binding when it is not object type. And also, it's better to check Falsy or boolean before than the length of object.

// as-is
var isPublicPackage = functions(doc) {
    return Object.keys(doc.binding).length == 0 && doc.publish;
}

// to-be
var isPublicPackage = functions(doc) {
    return doc.binding && doc.publish && Object.keys(doc.binding).length == 0;
}

I confirmed that CouchDB 2.3.1 and 3.3.3 don't print it out during re-building the index.

Related issue and scope

My changes affect the following components

Types of changes

Checklist:

rabbah commented 2 months ago

Thanks @dorbae for the fix