<commit_before># Copyright (c) 2021, Frappe Technologies and contributors
# License: MIT. See LICENSE
import frappe
from tenacity import retry, retry_if_exception_type, stop_after_attempt
from frappe.model.document import Document


class AccessLog(Document):
	pass


@frappe.whitelist()
@frappe.write_only()
@retry(
	stop=stop_after_attempt(3), retry=retry_if_exception_type(frappe.DuplicateEntryError)
)
def make_access_log(
	doctype=None,
	document=None,
	method=None,
	file_type=None,
	report_name=None,
	filters=None,
	page=None,
	columns=None,
):

	user = frappe.session.user
	in_request = frappe.request and frappe.request.method == "GET"

	doc = frappe.get_doc(
		{
			"doctype": "Access Log",
			"user": user,
			"export_from": doctype,
			"reference_document": document,
			"file_type": file_type,
			"report_name": report_name,
			"page": page,
			"method": method,
			"filters": frappe.utils.cstr(filters) if filters else None,
			"columns": columns,
		}
	)
	doc.insert(ignore_permissions=True)

	# `frappe.db.commit` added because insert doesnt `commit` when called in GET requests like `printview`
	# dont commit in test mode
	if not frappe.flags.in_test or in_request:
		frappe.db.commit()<commit_msg>perf: Use db_insert to make Access Logs instead<commit_after># Copyright (c) 2021, Frappe Technologies and contributors
# License: MIT. See LICENSE
import frappe
from frappe.utils import cstr
from tenacity import retry, retry_if_exception_type, stop_after_attempt
from frappe.model.document import Document


class AccessLog(Document):
	pass


@frappe.whitelist()
@frappe.write_only()
@retry(
	stop=stop_after_attempt(3), retry=retry_if_exception_type(frappe.DuplicateEntryError)
)
def make_access_log(
	doctype=None,
	document=None,
	method=None,
	file_type=None,
	report_name=None,
	filters=None,
	page=None,
	columns=None,
):
	user = frappe.session.user
	in_request = frappe.request and frappe.request.method == "GET"

	frappe.get_doc({
		"doctype": "Access Log",
		"user": user,
		"export_from": doctype,
		"reference_document": document,
		"file_type": file_type,
		"report_name": report_name,
		"page": page,
		"method": method,
		"filters": cstr(filters) or None,
		"columns": columns,
	}).db_insert()

	# `frappe.db.commit` added because insert doesnt `commit` when called in GET requests like `printview`
	# dont commit in test mode
	if not frappe.flags.in_test or in_request:
		frappe.db.commit()
{'fraction_non_alphanumeric': 0.11395540875309662, 'fraction_numerical': 0.004128819157720892, 'mean_word_length': 5.444148936170213, 'pattern_counts': {'":': 20, '<': 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': '5618973', 'n_tokens_mistral': 896, 'n_tokens_neox': 860, 'n_words': 209}