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

Hide extraneous GCN plumbing from returned objects #2217

Closed
adam-sandor opened this issue Apr 13, 2017 · 8 comments
Closed

Hide extraneous GCN plumbing from returned objects #2217

adam-sandor opened this issue Apr 13, 2017 · 8 comments
Assignees
Labels
api: storage Issues related to the Cloud Storage API. core type: question Request for information or clarification. Not an issue.

Comments

@adam-sandor
Copy link

Fetching a list of files from my bucket produces 271K of JSON output from the server. And I just have 4 files in the bucket.
The data includes things like the complete description of the bucket itself (per every file) or the description of the googlecloud storage library (authors, dependencies, etc). Some of this is probably not loaded from the server but is added by the node api library. Even if that doesn't lead to network traffic it's still unnecessary and inconvenient when I try to find the relevant data. The screenshot below show the data structure with most elements collapsed. None of those elements are relevant for listing files in the bucket. I only want to see the data that is printed by gsutil when doing ls.

https://www.dropbox.com/s/4dgpu7jh8z6lb9h/Screen%20Shot%202017-04-13%20at%2013.29.58.png?dl=0

I might be missing some option or parameter that would limit the output from getFiles.

Environment details

  • OS: OSX
  • Node.js version: 7.2.0
  • npm version: 3.10.9
  • google-cloud-node version: 1.0.0

Steps to reproduce

var storage = require('@google-cloud/storage');
var fs = require('fs');

var gcs = storage({
    projectId: 'MYPROJECT'
});

var bucket = gcs.bucket('MYBUCKET');

bucket.getFiles(function(err, files) {
    if (!err) {
        fs.writeFileSync("files.json", JSON.stringify(files))
    } else {
        console.error(err)
    }
});
@stephenplusplus
Copy link
Contributor

There is a lot of stuff on the object-- some is plumbing that enables our API to function. The only thing that's really meant for the user is the metadata property, which is the API's raw record of the resource.

In the context of getFiles(), the API response returns all of the metadata for each file. If we didn't include it on the object, it would require further API calls to download that information. To find the data you need, you should look into to the metadata object. In the case that you just want names, it's a simple map over the response:

bucket.getFiles(function(err, files) {
    if (!err) {
        var fileMetadataObjects = files.map(function(file) {
            return file.metadata
        })
        fs.writeFileSync("files.json", JSON.stringify(fileMetadataObjects))
    } else {
        console.error(err)
    }
})

And of course, if you just want the name, you can use file.metadata.name or any other properties that are relevant for your use.

@stephenplusplus stephenplusplus added api: storage Issues related to the Cloud Storage API. type: question Request for information or clarification. Not an issue. labels Apr 13, 2017
@stephenplusplus
Copy link
Contributor

Just to address the 271,000 lines of JSON, though, I'm not particularly thrilled about that. From a quick test, the output of one file for me was about 1,200 lines. I'll re-open so we can define those huge objects as non-enumerable, so they're hidden from the output.

@stephenplusplus stephenplusplus changed the title Bucket API getFiles returns huge amount of unnecessary data Hide extraneous GCN plumbing from returned objects Apr 13, 2017
@lukesneeringer lukesneeringer added the priority: p2 Moderately-important priority. Fix may not be included in next release. label Apr 13, 2017
@adam-sandor
Copy link
Author

Ok so do I understand correctly that only the metadata is actually downloaded from the server?

@stephenplusplus
Copy link
Contributor

Yes, everything else is state and internal data.

@adam-sandor
Copy link
Author

Cool, then it was just me panicking :)
Still would be user friendlier to not have that metadata in the request I think.

@lukesneeringer
Copy link
Contributor

This issue was moved to googleapis/nodejs-storage#19

@stephenplusplus
Copy link
Contributor

This would be a change in @google-cloud/common that would affect all of the modules, so I'll re-open this issue here.

@stephenplusplus
Copy link
Contributor

This issue was moved to googleapis/nodejs-common#13.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. core type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

4 participants