<commit_before>import os.path
from couchdbkit import FileSystemDocsLoader, ResourceConflict, Document

def max_num_for(db, prefix):
    result = db.view('counter/max_value', key=prefix).one()
    
    if result is None:
        return 0
    else:
        return result['value']

def get_new_id(db, prefix):
    return "%s-%d" % (prefix, max_num_for(db, prefix) + 1)

def save_doc_with_autoincremented_id(doc, db, prefix):
    if '_rev' in doc:
        db.save_doc(doc)
    else:
        if '_id' not in doc:
            doc['_id'] = get_new_id(db, prefix) 
        
        while True:
            try:
                db.save_doc(doc)
                break
            except ResourceConflict:
                doc['_id'] = get_new_id(db, prefix)
                
def save_model_with_autoincremented_id(doc, prefix):
    db = doc.get_db()
    if '_rev' in doc:
        doc.save()
    else:
        if '_id' not in doc:
            doc._id = get_new_id(db, prefix) 
        
        while True:
            try:
                doc.save()
                break
            except ResourceConflict:
                doc._id = get_new_id(db, prefix)<commit_msg>taburet.counter сохраняет модели через базовый класс, чтобы избежать рекурсии<commit_after>import os.path
from couchdbkit import FileSystemDocsLoader, ResourceConflict, Document

def max_num_for(db, prefix):
    result = db.view('counter/max_value', key=prefix).one()
    
    if result is None:
        return 0
    else:
        return result['value']

def get_new_id(db, prefix):
    return "%s-%d" % (prefix, max_num_for(db, prefix) + 1)

def save_doc_with_autoincremented_id(doc, db, prefix):
    if '_rev' in doc:
        db.save_doc(doc)
    else:
        if '_id' not in doc:
            doc['_id'] = get_new_id(db, prefix) 
        
        while True:
            try:
                db.save_doc(doc)
                break
            except ResourceConflict:
                doc['_id'] = get_new_id(db, prefix)
                
def save_model_with_autoincremented_id(doc, prefix):
    db = doc.get_db()
    if '_rev' in doc:
        Document.save(doc)
    else:
        if '_id' not in doc:
            doc._id = get_new_id(db, prefix) 
        
        while True:
            try:
                Document.save(doc)
                break
            except ResourceConflict:
                doc._id = get_new_id(db, prefix)
{'fraction_non_alphanumeric': 0.09774436090225563, 'fraction_numerical': 0.001670843776106934, 'mean_word_length': 1.8110328638497653, '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': '5694175', 'n_tokens_mistral': 783, 'n_tokens_neox': 759, 'n_words': 185}