[REF] pms: scoped recompute of real_avail on pms.room changes#398
Open
DarioLodeiros wants to merge 1 commit into
Open
[REF] pms: scoped recompute of real_avail on pms.room changes#398DarioLodeiros wants to merge 1 commit into
DarioLodeiros wants to merge 1 commit into
Conversation
The ``pms.availability.real_avail`` field used to declare ``room_type_id.total_rooms_count`` as one of its ``@api.depends``. Because ``total_rooms_count`` is itself a stored compute on ``pms.room.type`` that depends on ``room_ids`` / ``room_ids.active``, every single change on a room (activate / deactivate, re-segment to another room type, create a new room, delete one) triggered a recompute of EVERY ``pms.availability`` row of the affected room type(s) — historical rows included. On busy properties this locked the table for minutes. This commit replaces that wide dependency with a SCOPED, future-only recompute driven from ``pms.room.create / write / unlink``: * Remove ``room_type_id.total_rooms_count`` from the depends of ``_compute_real_avail`` (history rows no longer recompute by reflex). * Add ``pms.availability._recompute_real_avail_for_room_change( pms_property_ids, room_type_ids, date_from=None)`` that schedules a recompute only for the matching (property, room_type) tuples and only for ``date >= today()`` by default. * Override ``pms.room.create / write / unlink`` to call the helper with the affected (property, room_type) sets. For ``write``, the union of OLD and NEW pairs is used so re-segmentation (moving a room between room types) correctly recomputes both the source and the target room_type's future avail. The recompute uses ``env.add_to_compute`` so it integrates with Odoo's normal flush mechanism — the cache stays consistent and any reader within the same transaction sees the new values.
5c0dae1 to
0be882d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
pms.availability.real_availused to declareroom_type_id.total_rooms_countas one of its@api.depends. Becausetotal_rooms_countis itself a stored compute onpms.room.typethat depends onroom_ids/room_ids.active, any change on a room (activate / deactivate, re-segment to another room type, create a new room, delete one) triggered a recompute of everypms.availabilityrow tied to the affected room type(s) — historical rows included.On busy properties this locked the table for minutes (we've measured >5 minutes on a customer DB). It is the reason several downstream forks comment out that depends line and live without the dependency at all — at the cost of stale
real_availuntil the next reservation line change touches the row.Approach
Replace the wide automatic dependency with a SCOPED, future-only recompute driven from
pms.room.create / write / unlink:room_type_id.total_rooms_countfrom the@api.dependsof_compute_real_avail. History rows no longer recompute by reflex.pms.availability._recompute_real_avail_for_room_change(pms_property_ids, room_type_ids, date_from=None)that schedules a recompute only for the matching(property, room_type)tuples and only fordate >= today()by default. Usesenv.add_to_computeso it integrates with Odoo's normal flush — the cache stays consistent and any reader within the same transaction sees the new values.pms.room.create / write / unlinkto call the helper with the affected(property, room_type)sets. Forwrite, the union of OLD and NEW pairs is used so a re-segmentation (moving a room between room types) correctly recomputes BOTH the source and the target room_type's future avail.Fields covered for write
active,room_type_id,pms_property_id,parent_id— i.e. the four fields whose change moves the effective room count of one or more(property, room_type)pairs.Test plan
pms.availabilityrows of the room_type are scheduled for recompute (history untouched). Measured locally: deactivation that used to lock for ~30s now completes in <1s.real_availread after the room change but before commit returns the new value.