<commit_before>﻿using System;
using System.Threading.Tasks;
using KotoriCore.Commands;
using KotoriCore.Domains;
using KotoriCore.Exceptions;
using KotoriCore.Helpers;

namespace KotoriCore.Database.DocumentDb
{
    partial class DocumentDb
    {
        async Task<CommandResult<SimpleDocument>> HandleAsync(GetDocument command)
        {
            var projectUri = command.ProjectId.ToKotoriUri();

            var project = await FindProjectAsync(command.Instance, projectUri);

            if (project == null)
                throw new KotoriValidationException("Project does not exist.");

            var d = await FindDocumentByIdAsync(command.Instance, projectUri, command.Identifier.ToKotoriUri());

            if (d == null)
                throw new KotoriDocumentException(command.Identifier, "Document not found.");
            
            return new CommandResult<SimpleDocument>
            (
                new SimpleDocument
                (
                    new Uri(d.Identifier).ToKotoriIdentifier(),
                    d.Slug,<commit_msg>GetDocument command optimized, close #19<commit_after>﻿using System;
using System.Threading.Tasks;
using KotoriCore.Commands;
using KotoriCore.Domains;
using KotoriCore.Exceptions;
using KotoriCore.Helpers;

namespace KotoriCore.Database.DocumentDb
{
    partial class DocumentDb
    {
        async Task<CommandResult<SimpleDocument>> HandleAsync(GetDocument command)
        {
            var projectUri = command.ProjectId.ToKotoriUri();
            var d = await FindDocumentByIdAsync(command.Instance, projectUri, command.Identifier.ToKotoriUri());

            if (d == null)
                throw new KotoriDocumentException(command.Identifier, "Document not found.");
            
            return new CommandResult<SimpleDocument>
            (
                new SimpleDocument
                (
                    new Uri(d.Identifier).ToKotoriIdentifier(),
                    d.Slug,
{'fraction_non_alphanumeric': 0.0792280345352971, 'fraction_numerical': 0.001015744032503809, 'mean_word_length': 2.3732876712328768, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3222583', 'n_tokens_mistral': 493, 'n_tokens_neox': 478, 'n_words': 111}