*: test_website, website_blog (test perfs) An error regarding tests was not catch during httpocalypse [1] review. The test query counts were lowered in website by 2 everywhere, but it shouldn't have as there were no SQL perf improvement from this refactoring regarding website. The query count actually decreased because the test-only SQL Savepoints got divided by 2, probably thanks to a low level test improvement in the PR. But outside of tests, there were no SQL Query gained. This should have been reflected in the `EXTRA_REQUEST` variable instead. Before: Savepoint > Rollback > Savepoint > [Actual SQL Queries] > Rollback After: Savepoint > [Actual SQL Queries] > Rollback It is important to fix it because: 1. (Minor) There is a de-sync between the query count in the test and the actual query count (in the logs outside of tests), making it hard to figure. 2. (Major) Some controller got then wrongly lowered to 0 query counts instead of 2. An incoming PR in master would then make those tests expects negative query counts, which doesn't make any sense. [1]: https://github.com/odoo/odoo/pull/78857 Note that the exact commit can't be found by bisect as those don't work on their own, DB can't be started due to circular import. Part-of: odoo/odoo#87856
48 lines
2.4 KiB
Python
48 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.addons.website.tests.test_performance import UtilPerf
|
|
import random
|
|
|
|
|
|
class TestBlogPerformance(UtilPerf):
|
|
def setUp(self):
|
|
super().setUp()
|
|
# if website_livechat is installed, disable it
|
|
if 'channel_id' in self.env['website']:
|
|
self.env['website'].search([]).channel_id = False
|
|
|
|
def test_10_perf_sql_blog_standard_data(self):
|
|
self.assertEqual(self._get_url_hot_query('/blog'), 28)
|
|
self.assertEqual(self._get_url_hot_query('/blog', cache=False), 27)
|
|
|
|
def test_20_perf_sql_blog_bigger_data_scaling(self):
|
|
BlogPost = self.env['blog.post']
|
|
BlogTag = self.env['blog.tag']
|
|
blogs = self.env['blog.blog'].search([])
|
|
blog_tags = BlogTag.create([{'name': 'Blog Tag Test %s' % i} for i in range(1, 20)])
|
|
BlogPost.create([{'name': 'Blog Post Test %s' % i, 'is_published': True, 'blog_id': blogs[i % 2].id} for i in range(1, 20)])
|
|
blog_posts = BlogPost.search([])
|
|
for blog_post in blog_posts:
|
|
blog_post.tag_ids += blog_tags
|
|
blog_tags = blog_tags[:-1]
|
|
self.assertEqual(self._get_url_hot_query('/blog'), 28)
|
|
self.assertEqual(self._get_url_hot_query('/blog', cache=False), 27)
|
|
self.assertEqual(self._get_url_hot_query(blog_post[0].website_url), 32)
|
|
self.assertEqual(self._get_url_hot_query(blog_post[0].website_url, cache=False), 31)
|
|
|
|
def test_30_perf_sql_blog_bigger_data_scaling(self):
|
|
BlogPost = self.env['blog.post']
|
|
BlogTag = self.env['blog.tag']
|
|
blogs = self.env['blog.blog'].search([])
|
|
blog_tags = BlogTag.create([{'name': 'New Blog Tag Test %s' % i} for i in range(1, 50)])
|
|
BlogPost.create([{'name': 'New Blog Post Test %s' % i, 'is_published': True, 'blog_id': blogs[random.randint(0, 1)].id} for i in range(1, 100)])
|
|
blog_posts = BlogPost.search([])
|
|
for blog_post in blog_posts:
|
|
blog_post.write({'tag_ids': [[6, 0, random.choices(blog_tags.ids, k=random.randint(0, len(blog_tags)))]]})
|
|
|
|
self.assertLessEqual(self._get_url_hot_query('/blog'), 29)
|
|
self.assertLessEqual(self._get_url_hot_query('/blog', cache=False), 28)
|
|
self.assertLessEqual(self._get_url_hot_query(blog_post[0].website_url), 34)
|
|
self.assertLessEqual(self._get_url_hot_query(blog_post[0].website_url, cache=False), 33)
|