entities – Do fields that are not displayed affect rendering performance?

This is a general question about how Drupal renders content. Say I have a content type with 20 fields, including some entity references, text fields, integers, and so on.

When I have a lot of fields on a content type, I know that each field slows down operations like saving the content type because each field has to be processed.

However, what about when Drupal renders the content type to display it? If I hide 19 of the 20 fields on “Manage Display” for the content type, will Drupal avoid processing all those fields and have the same performance as rendering a content type that only has 1 field?

hierarchy – Warehouse Management UX : Managing Warehouse Entities in Single Window Interface

Warehouse Management UX : Managing Warehouse Entities in Single Window Interface.

I am designing UI/UX for a warehouse management system.
As a warehouse consist of a hierarchy of containers as mentioned below.
Warehouse building -> Zone -> Aisle -> Bay -> Rack -> Shelve -> Bin

Other moveable containers (tote, cart, palette, Box)

I am looking forward to designing a single window interface
from which users can add / update and delete all hierarchical warehouse entities.

This application will be used by 3PL company staff who manages the warehouse.

In my current approach I have categorized warehouse entities into below mentioned categories.

  1. Layout (Zone, Aisle, Bay)
  2. Storage Unit (Rack, Shelf, Bin)
  3. Movable (Tote, palette, cart, Bin)

I have placed a dropdown at the top of the screen which will contain all of the above categories.
When a user selects any category, all the elements inside that category will be displayed in tabs besides the category selection dropdown.

Once the user selects a tab. A table will be displayed with the properties of the selected entity.
Wire frame example of the zone entity is attached below.

I have added textbox under each property heading so that user can enter a value and filter the records being displayed in the table.

enter image description here

Once a user clicks add entity instance or attempts to edit a existing entity instance available in the table. A pop up will be display to add and edit all the properties of the selected entity.
Below is the example of the pop-up.

enter image description here

I have Below doubts about my approach.

  1. Is this approach feasible for large amount of instances created for each entity considering its a warehouse management system?
  2. Is this the best way, to manage entities in hierarchy for a warehouse/inventory management ?
  3. Is this UI representation best for standard sized screen at warehouse terminals ?
  4. In the future we might display the inventory which will be present inside these respective warehouse
    entity in the same instance property table. Will this be a feasible approach for warehouse entity and its inventory management ?

Any suggestions are appreciated.

entities – Force a single value base field to be in a separate table?

Seems the following class is responsible for determining a separate field storage table:

DrupalCoreEntitySqlDefaultTableMapping::allowsSharedTableStorage

It returns a boolean based on the following 4 conditions:

public function allowsSharedTableStorage(FieldStorageDefinitionInterface $storage_definition) {
  return !$storage_definition->hasCustomStorage() && $storage_definition->isBaseField() && !$storage_definition->isMultiple() && !$storage_definition->isDeleted();
}

The only feasible solution would be to implement your own Storage handler and flag the basefield with "custom_storage" => TRUE

entities – hiding field -reference option limit

Helloo !
I am using the D7 reference option limit module. I have two fields “primary” and “secondary” and I managed to reduce the choices of secondary based on the value of primary using this module. Both of them are required field in the user registration form.

I have a small question, when I set no value for primary, I get for the secondary field: No options are available for the current form values. Try selecting different values for the following fields: Primary. This is the good behaviour that I want but I want to hide secondary when no value is set for primary instead of displaying this message..

Is that possible? In other words I want to keep secondary hidden until primary has a value.

c# – Is it acceptable to pass a “context object” through a pipeline of entities?

Overview

Domain-driven design prescribes modelling a particular domain with classes that contain both state and behaviour. Microsoft attempt to support this methodology in modern C# applications through EF Core, which allows constituting graphs of entity objects from a database.

I’m building an application where I model individual configurable business rules as entities. These individual rules belong to a “commission ruleset”, and the ruleset arranges these rules into a pipeline that sequentially perform updates on objects passed through that pipeline.

enter image description here

These rules depend on external services to lookup or calculate various things in order to do their job.

What is the best way to allow them to access these services, given they are DDD entities constituted from the database?

Does it make sense to pass through a context object alongside the object being updated which exposes all services that a business rule might require? This feels like it would be an anti-pattern but I can’t think of a better alternative.

Details

I’m working on a redesign of the commissions system at my company. This particular domain has a high degree of business complexity and low technical complexity, so I figured DDD was a good fit here.

Background

At our company, we have a number of product consultants (salesmen) that earn commission on orders they sell within a period (a month-long time period). Product consultants are each assigned to a particular commission plan which determines the commission rules that apply to them. A commission rule is a (potentially configurable) business rule that in some way impacts the commission they earn within a period. Commission rules are combined together to form a commission ruleset.

Requirement

Product consultants should be able to view their statement, which is a snapshot of the commission they’ve earned so far in the period along with any relevant information that factors into this (orders sold, performance targets met, etc.).

Attempted Solution

Following Microsoft’s recommendations for DDD-based architectural design, we created a number of classes to model the domain which:

  • Are mapped to and from the database using EF Core
  • Contain both state and relevant business logic (i.e. are not anaemic)

The diagram below shows a simplified view of how these entities look from a persistence point of view:

enter image description here

During statement generation, a set of record in the database are constituted to an object graph with this structure:

enter image description here

A basic statement is generated and then passed to CommissionRuleset, which sequentially passes the statement to each of the rules that compose it. As well as updating the calculated commission, these rules my potentially affect other parts of the statement that ultimately control how the statement is visually represented to the product consultant:

enter image description here

These rules need to be able access services that calculate their performance, lookup their previous payment records, etc. Right now, I handle this by making all those services available from the statement itself:

enter image description here

In this sense, each commission rule modifies the statement using data it accesses from the statement itself. This doesn’t feel like the cleanest solution, and it’s quickly turning Statement into a god class.

One potential alternative would be to somehow inject these services into the individual commission rules themselves, like this:

enter image description here

However, EF Core does not support injecting arbitrary services into entities during construction (yet), and even if it did, I’m not sure if it’s good practice to inject domain services into entity constructors.

The only practical remaining alternative I can think of is to pass a “context object” alongside the statement being generated, which would allow the business rules to get the data they need. So far all the external calculations/lookups these business rules require relate to the product consultant the statement is being generated for (performance calculations or records, payment records, etc.), so I could create at least create a nominally cohesive aggregate service (or context object) along the lines of IProductConsultantDataService or something.

Is this the best approach or is there a better alternative to this?


Sidenote: there are some parts of my redesign that I feel iffy about, but the decision to model business rules as separate classes that can be arranged in a pipeline feels incredibly “right” for this particular system.

There are many business rules in this system, and new ones are likely to come along in the future. New rules can be encapsulated as their own individual classes, added to the pipeline independently, removed independently, tested in isolation; arbitrary sets of rules with arbitrary configurations can be arranged in arbitrary orders within a ruleset, and using EF Core this all cleanly persists and reconstitutes from the database.

I’m very happy with this particular aspect of the design.

javascript – Clean Architecture in NodeJS – How to approach the next step (use-cases) after entities?

I’ve been trying to learn about software architecture and after watching multiple talks of Robert C. Martin I fell in love with his concepts and Test Driven Development.

For a couple days now I’ve been trying to follow the Clean Architecture principles while building a chat-application server that used to be one big monolith mess. But I have the gut feeling I’m not understanding it at all and have no clue how to approach the next step after entities: Use Cases.

So far I’ve come up with 4 entities:
message, room, user & uuid.

A user should be able to create a room and add a message to the room. A user should also be able to join an existing room and add a message in this existing room.

An example of the room entity:

./entities/room/room.spec.js

"use strict";
const chai = require("chai");
chai.use(require("chai-uuid"));
const expect = chai.expect;

const makeMessage = require('./index.js');

describe('message', function() {

    const message = makeMessage({
        content: "Hello World!",
        sender: "#9119BBXX1212"
    });

    it('must contain a non-empty string', function() {
        expect(message.getContent()).to.be.a('string').and.not.be.empty;
    });

    it('must contain a valid UUID', function() {
        expect(message.getId()).to.be.a.uuid();
    })

    it('must contain a sender', function() {
        expect(message.getSender()).to.be.a('string');
    })

    it('must contain a created at date', function() {
        expect(message.getCreatedAt()).to.be.a('date');
    })

});

./entities/room/makeRoom.js

module.exports = function buildMakeRoom({uuid}) {

    return function makeRoom({messages = (), createdAt = new Date(), theUuid = uuid.generate()} = {}) {

        return Object.freeze({
            getId: () => theUuid,
            getCreatedAt: () => createdAt,
            getMessages: () => messages,
            addMessage: function(message) {
                messages.push(message);
            }
        })

    }

}

./entities/room/index.js

const buildMakeRoom = require('./makeRoom.js');
const uuid = require('../uuid/index.js');

const makeRoom = buildMakeRoom({uuid});
module.exports = makeRoom;

That’s what I think an entity in Node would look like. And it works great if I play with it a little. But what’s the next step? How do I make a Use Case based on this entity?

I’ve tried to play with the entities in the main file to get a feeling for what’s necessary. But I’m so confused:

const makeRoom = require('./entities/room/index.js');
const makeUser = require('./entities/user/index.js');
const makeMessage = require('./entities/message/index.js');

// #Repository - Store Rooms and Users
const rooms = {};
const users = {};

// #User - Create A User
const userOne = makeUser();
users(userOne.getId()) = userOne;

// #Room - Create A Room
const room = makeRoom();
rooms(room.getId()) = room;

// #User - Join A Room
userOne.setCurrentRoom(room.getId());
userOne.setJoinedRoom(true);

// #Message - Create a Message
const message = makeMessage({
    sender: userOne.getId(),
    content: "Hello World!"
})

// #Room - Add a Message
rooms(userOne.getCurrentRoom()).addMessage(message);

// #User - Create A User
const userTwo = makeUser();
users(userTwo.getId()) = userTwo;

// #User - Join A Room
userTwo.setCurrentRoom(room.getId());
userTwo.setJoinedRoom(true);

// #Message = Create A Message
const secondMessage = makeMessage({
    sender: userTwo.getId(),
    content: "Whatsupp World!"
})

// #Room - Add a Message
rooms(userTwo.getCurrentRoom()).addMessage(secondMessage)

// #Room - Display Messages
rooms(room.getId()).getMessages().forEach(message => {
    // Display the Messages to Console (This could be a UI as well. Like an web-interface)
    console.log(message.getCreatedAt(), message.getSender(), message.getContent());
})

I would appreciate it so much if you could help me out!

TL;DR: After writing your entities with TDD and Clean Architecture. What should be the next step to create a good Use Case?

c# – how to order entities by their distance from 0 on the x axis

I’m creating an infinite runner game in which you control several characters at once. Right now when you press the spacebar, they all jump at once but, I want them to jump at separately, one after the other from right to left(largest x to smallest x) so I need to order them in some way to represent that.

I tried using bubble sort to do this with no success so I tried my own approach where I scan the screen for the x position of the characters and assign their order to the number of passes the loop has gone through:

public void SetJumpOrder()
    {
        int pass = 0;

        foreach (Alien a in handler.aliens)
        {
            for (int i = 1000; i > 0; i--)
            {
                if (i == a.position.X) a.jumpOrder = pass;
            }
            pass++;
        }
    }

The code above didn’t work because it just gave the order of the aliens list instead. Any suggestions?

entities – Problem regarding saving field data programmatically

I’m developing a module for Drupal 9 which creates nodes. In order to achieve that, I added the field types, field formatters, field widgets, a form display, a view display as well as configuration for the fields inside the mymodule/config/install directory (e.g. field.field.node.foo.field_bar.yml and field.storage.node.field_bar.yml). Then, based on some business logic, I’m adding new nodes in PHP as follows (for simplicity, here is only one custom field):

use DrupalnodeEntityNode;
$node = Node::create((
  'type' => 'foo',
  'title' => 'Example',
  'status' => 1,
  'langcode' => 'en',
  'field_bar' => 'Content of bar',
));
$node->save();

Creating nodes and setting the title works fine. For some reason, I can see the values for field_bar in the database (table node__field_bar contains rows where field_bar_value is set as intended) but they don’t appear inside the corresponding text input when I’m editing a node. Also if I want to output the field’s value, it is empty. However, when I just create a new foo item using Drupal’s GUI, everything seems to work as intended. Therefore, I think the error is rather in the above code than in the field’s setup (field type class, yml configuration files, etc.). Feel free to correct me if this assumption is wrong. Thanks in advance!

java – Is calling Session::evict() on Hibernate entities considered bad practice?

I’m using Hibernate in my application. When calling the setters on Hibernate entities that are in “managed” state, it will eventually write the changes back to database when the transaction is getting committed, even without explicitly calling Session::update().

Sometimes, I have to call Session::evict() in my code to avoid accidentally writing these changes into database. However, I have some problems:

  • I have to worry about the state of these entities all the time. When passing entities between services and DAOs, I need to keep track of the states of them. This increase the complexity of development.
  • Writing test cases became harder. Asserting the state of entities that must be “managed” or “detached” state is tedious and annoying.

Is calling Session::evict() considered bad practice? If so, what’s the best way to avoid it?