Edgewall Software
Modify

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#11681 closed enhancement (fixed)

Cache env.get_version

Reported by: anonymous Owned by: Ryan J Ollos
Priority: low Milestone: 0.12.6
Component: general Version: 1.0.1
Severity: trivial Keywords: cache get_version timeline ticket environment
Cc:
Release Notes:

The value of TicketSystem.must_preserve_newlines is cached in order to avoid a database hit on every access for the case that [ticket] preserve_newlines = default (the default value).

API Changes:

Added database_version and database_initial_version attributes to the Environment class (1.0.2/1.1.2). These are lazily-evaluated attributes that cache the value retrieved from the database by Environment.get_version. The method get_version will be made private in release 1.3.1.

Description

When viewing the timeline, for each ticket it finds it request env.get_version which runs a sql-query:

SELECT value FROM system WHERE name='initial_database_version'

Couldn't this info be cached somewhere instead? (maybe inside the get_version function?) it seems highly unlikely the value will change…

I know the DB probably will have the query in its cache and its a tiny query, but its still unnecessary to ask over and over again

Reference: http://trac.edgewall.org/browser/tags/trac-1.0.1/trac/ticket/web_ui.py#L130 http://trac.edgewall.org/browser/tags/trac-1.0.1/trac/env.py#L586

Attachments (0)

Change History (9)

comment:1 Changed 4 years ago by Ryan J Ollos

Owner: set to Ryan J Ollos
Status: newassigned

Yes, we can fix it with some property caching.

comment:2 Changed 4 years ago by Ryan J Ollos

Proposed changes in log:rjollos.git:t11681.

We might consider:

  • Renamed Environment.versionEnvironment.database_version
  • Renamed Environment.initial_versionEnvironment.database_initial_version

That is because the Environment has a version as well: trunk/trac/env.py@12843:47#L45.

I haven't checked the issue on 0.12-stable, but we could fix it there too if it's important.

comment:3 in reply to:  2 Changed 4 years ago by Jun Omae

Keywords: environment added; env.get_version removed

Replying to rjollos:

Proposed changes in log:rjollos.git:t11681.

In [92db8fb6f/rjollos.git], I think Environment.version should return new version after upgrade_environment.

We might consider:

  • Renamed Environment.versionEnvironment.database_version
  • Renamed Environment.initial_versionEnvironment.database_initial_version

That is because the Environment has a version as well: trunk/trac/env.py@12843:47#L45.

Agreed. I think that's good naming.

I haven't checked the issue on 0.12-stable, but we could fix it there too if it's important.

0.12-stable has the same issue. Also, preventing the query is to set [ticket] preserve_newlines to enabled or disabled.

comment:4 Changed 4 years ago by anonymous

Missed that option, thanks for a quick fix!

comment:5 Changed 4 years ago by Ryan J Ollos

Revised changes in log:rjollos.git:t11681.1, and for 0.12 in log:rjollos.git:t11681_0.12.

comment:6 Changed 4 years ago by Ryan J Ollos

API Changes: modified (diff)
Milestone: 1.0.20.12.6
Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Fix for 0.12-stable committed in [12985] (record-only merges in [12986:12987]). Fix for 1.0-stable committed in [12989], merged in [12990].

comment:7 Changed 4 years ago by Ryan J Ollos

API Changes: modified (diff)

comment:8 Changed 4 years ago by Ryan J Ollos

Removed use of deprecated get_version in EnvironmentStub class in [13643]. Merged to trunk in [13644].

comment:9 in reply to:  8 Changed 4 years ago by Ryan J Ollos

Replying to rjollos:

Removed use of deprecated get_version in EnvironmentStub class in [13643]. Merged to trunk in [13644].

Environment.database_version is lazily-evaluated, so the database may not be reset in tearDown if the database version is changed in the test case. Fixed on 1.0-stable in [13921], on trunk in [13923].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.