<commit_before>package api

import (
	"bytes"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/smira/aptly/deb"
	"io"
	"os"
	"os/exec"
)

// GET /api/graph
func apiGraph(c *gin.Context) {
	var (
		err    error
		output []byte
	)

	graph, err := deb.BuildGraph(context.CollectionFactory())
	if err != nil {
		c.JSON(500, err)
		return
	}

	buf := bytes.NewBufferString(graph.String())

	command := exec.Command("dot", "-Tpng")
	command.Stderr = os.Stderr<commit_msg>Lock collections before building graph. #169<commit_after>package api

import (
	"bytes"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/smira/aptly/deb"
	"io"
	"os"
	"os/exec"
)

// GET /api/graph
func apiGraph(c *gin.Context) {
	var (
		err    error
		output []byte
	)

	factory := context.CollectionFactory()

	factory.RemoteRepoCollection().RLock()
	defer factory.RemoteRepoCollection().RUnlock()
	factory.LocalRepoCollection().RLock()
	defer factory.LocalRepoCollection().RUnlock()
	factory.SnapshotCollection().RLock()
	defer factory.LocalRepoCollection().RUnlock()
	factory.PublishedRepoCollection().RLock()
	defer factory.PublishedRepoCollection().RUnlock()

	graph, err := deb.BuildGraph(factory)
	if err != nil {
		c.JSON(500, err)
		return
	}

	buf := bytes.NewBufferString(graph.String())

	command := exec.Command("dot", "-Tpng")
	command.Stderr = os.Stderr
{'fraction_non_alphanumeric': 0.15892053973013492, 'fraction_numerical': 0.006746626686656672, 'mean_word_length': 4.276679841897233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '47434', 'n_tokens_mistral': 505, 'n_tokens_neox': 485, 'n_words': 90}