frostyx / copr / copr

Forked from copr/copr 7 years ago
Clone

bd5413c cli: print JSON list continuously, not at once when all items are fetched

1 file Authored by frostyx 3 years ago, Committed by frostyx 3 years ago,
    cli: print JSON list continuously, not at once when all items are fetched
    
    For performance reasons we cannot simply add everything to a list and then
    use `json_dumps` function to print all JSON at once. For large projects this
    would mean (tens) of minutes of no output, which is not user-friendly.
    
    Instead, let's utilize `json_dumps` to convert each object to a JSON
    string and print it immediately. By doing so, we need to manually take
    care of opening and closing list brackets and separators.
    
    Within this commit, I also did some unrelated changes that were
    necessary because the code is too tied together.
    
    We didn't print a valid JSON output for large projects that required
    paginating over more than just one page. The problem was repeatedly
    opening and closing the main list. This commit fixes it.
    
    I simplified the `JsonPrinter` as much as possible since 1) it was really
    hard to understand, and 2) there was a _leak_ causing iteration over
    the whole `self.output_info` over and over again each time a new item
    was added, resulting in the printer being increasingly slower.
    
    I also updated the printer usage for listing builds. It doesn't make
    sense to create a new printer for each page of builds. Instead, we
    should simply create a printer, use it for the whole loop and finish
    after that.
    
        
file modified
+45 -25