MCPcopy Create free account
hub / github.com/Debian/dcs / writeToDisk

Function writeToDisk

cmd/dcs-web/querymanager.go:671–760  ·  view source on GitHub ↗
(queryid string)

Source from the content-addressed store, hash-verified

669}
670
671func writeToDisk(queryid string) error {
672 // Get the slice with results and unset it on the state so that processing can continue.
673 stateMu.Lock()
674 s := state[queryid]
675 pointers := make([]resultPointer, 0, s.numResults())
676 for _, bstate := range s.perBackend {
677 pointers = append(pointers, bstate.resultPointers...)
678 bstate.tempFileWriter.Flush()
679 }
680 if len(pointers) == 0 {
681 log.Printf("[%s] not writing, no results.\n", queryid)
682 stateMu.Unlock()
683 return nil
684 }
685 idx := 0
686
687 // For each full package (i3-wm_4.8-1), store only the newest version.
688 packageVersions := make(map[string]dpkgversion.Version)
689 for _, bstate := range s.perBackend {
690 for pkg, _ := range bstate.allPackages {
691 underscore := strings.Index(pkg, "_")
692 name := pkg[:underscore]
693 version, err := dpkgversion.Parse(pkg[underscore+1:])
694 if err != nil {
695 log.Printf("[%s] parsing version %q failed: %v\n", queryid, pkg[underscore+1:], err)
696 continue
697 }
698
699 if bestversion, ok := packageVersions[name]; ok {
700 if dpkgversion.Compare(version, bestversion) > 0 {
701 packageVersions[name] = version
702 }
703 } else {
704 packageVersions[name] = version
705 }
706 }
707 }
708
709 packages := make([]string, len(packageVersions))
710 for pkg, _ := range packageVersions {
711 packages[idx] = pkg
712 idx++
713 }
714 // TODO: sort by ranking as soon as we store the best ranking with each package. (at the moment it’s first result, first stored)
715 s.allPackagesSorted = packages
716 state[queryid] = s
717 stateMu.Unlock()
718
719 log.Printf("[%s] sorting, %d results, %d packages.\n", queryid, len(pointers), len(packages))
720 pointerSortingStarted := time.Now()
721 sort.Sort(pointerByRanking(pointers))
722 log.Printf("[%s] pointer sorting done (%v).\n", queryid, time.Since(pointerSortingStarted))
723
724 // TODO: it’d be so much better if we would correctly handle ESPACE errors
725 // in the code below (and above), but for that we need to carefully test it.
726 ensureEnoughSpaceAvailable()
727
728 pages := int(math.Ceil(float64(len(pointers)) / float64(resultsPerPage)))

Callers 1

storeProgressFunction · 0.85

Calls 8

ParseFunction · 0.92
CompareFunction · 0.92
pointerByRankingTypeAlias · 0.85
sendPaginationUpdateFunction · 0.85
numResultsMethod · 0.80
FlushMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected