Help me understand `Governor::execute()` function

this is the execute() function from openzeppelin Governor contract.

    function execute( address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash ) public payable virtual returns (uint256) {

        uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);

        _validateStateBitmap( proposalId, _encodeStateBitmap(ProposalState.Succeeded) | _encodeStateBitmap(ProposalState.Queued) );

        // mark as executed before calls to avoid reentrancy
        _proposals[proposalId].executed = true;

        // before execute: register governance call in queue.
        if (_executor() != address(this)) {

            for (uint256 i = 0; i < targets.length; ++i) {

                if (targets[i] == address(this)) {

                    _governanceCall.pushBack( keccak256(calldatas[i]) );

                }

            }
        }


        _executeOperations(proposalId, targets, values, calldatas, descriptionHash);

        // after execute: cleanup governance call queue.
        if (_executor() != address(this) && !_governanceCall.empty()) {

            _governanceCall.clear();

        }

        emit ProposalExecuted(proposalId);

        return proposalId;

    }

the part that confuses me is before and after _executeOperations() logic:

        // before execute: register governance call in queue.
        if (_executor() != address(this)) {

            for (uint256 i = 0; i < targets.length; ++i) {

                if (targets[i] == address(this)) {

                    _governanceCall.pushBack( keccak256(calldatas[i]) );

                }

            }
        }


        _executeOperations(proposalId, targets, values, calldatas, descriptionHash);

        // after execute: cleanup governance call queue.
        if (_executor() != address(this) && !_governanceCall.empty()) {

            _governanceCall.clear();

        }

i really want to know why we should store the calldata at end of the queue(DoubleEndedQueue.Bytes32Deque) and then clear it. basically why should the execute() function contain such logic? what is it for?

Not sure if this is still relevant, but this _governanceCall is relevant as it's used in some other functions to verify that we are indeed in a governance action (execution of a passed proposal) while executing certain actions.

Some special functions in the Governor have the onlyGovernance modifier (rn only relay on the base governor), which make sure that the given operation is in fact part of a proposal execution that is being executed during the current transaction. Even though it lives on storage, the state of the _governanceCall field is only maintained during the execution of a single transaction.

So this logic makes sure that some operations can only be executed as a governance action, i.e. by making a proposal and voting through the governor itself.