Closed (duplicate)
Project:
Drupal core
Version:
9.4.x-dev
Component:
node system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
8 Jul 2009 at 21:39 UTC
Updated:
6 May 2022 at 08:31 UTC
Jump to comment: Most recent
Comments
Comment #1
michelleJust a note to not forget that forum.module makes use of sticky.
Michelle
Comment #2
damien tournoud commentedI don't believe we want to make Drupal slower then it already is. A flag field type in core: why not. Converting sticky and promote to it: no way ;)
Comment #3
catchSo for this not to be a performance drain, we need the field module to hook_schema_alter() the flag columns onto the table for the fieldable entity (so {node}.sticky is owned by flag_field.module's hook_schema() - and when a new field / field instance is created, we do db_add_field() to put it there - and the same for removal.
Then the field module's hook_field_load() hook_field_insert() hook_field_save() handle updating the sticky/promoted etc. statuses on the entity table. There may be another way to do this in field API which completely skips field storage for this stuff, which would save a duplicate insert/update - but I don't know how that's supposed to be done.
The other option would be materialized views in core, but that's not in CVS yet so I don't have high hopes.
This would be great though - you could rename the core 'flags' to something else, and add extra ones very easily, and it'd allow for things like a 'featured' column for users via the CCK/Field UI.
Forum queries wouldn't need to change - but we'd have to either prevent the 'sticky' flag from being removed altogether, or somehow integrate the flag field and forum module to sync up (which seems impossible without Views, so probably forcing sticky/promoted etc. to always exist is the best bet for now - even if you can rename them / remove them from the UI).
Comment #4
mikey_p commentedAlso $node->status any number of things that other modules add.
Comment #5
catchDamZ pointed out in irc we need indexes as well.
So would need to be db_add_field() and db_add_index() (and keep any composite indexes for the 'core' flags).
Comment #6
naheemsays commentedone again, flogging an issue I created, but #470580: Allow multiple content types for user blogs would benefit from such a thing (and also has something that can probably easily be expanded into a simple flag module).
For that issue, I was dissuaded to add more columns to the node table, but I am not really even a developler, so people who know better will know better.
Comment #7
catchWe can't use foreign keys in core, because MyISAM doesn't support them, and we need to add conditions on that other table, not just load it into the node object, so there's a real performance impact there. So I think if we have a generic way to add these flags to the node table via the field, then your blog patch could add a 'blog' field instance as a flag, and that would work (and this could be defined per content type, which bangpound's use case would allow for) - also you'd only get the extra field if blog.module was enabled - so sites without that need wouldn't suffer the extra column and index to maintain.
Having used flag module in contrib with views, I can confirm the queries you end up generating can be very, very ugly indeed, so I'm not sure why Crell thinks it's not a problem.
Comment #8
chx commentedNote that MySQL can not index across tables so if you have a big table you already denormalize anyways. I do not really care where I pull the flags out from, whether it's node or something else, I need to denormalize from several tables anyways.
Comment #9
josh waihi commentedThere are two scopes to consider, global and per content type (for node), naturally a global flag can be added as a column to the node or node_revision table but per content type would require another table to join, slowing things down a bit. For example, I never use sticky and don't see the use for it, but as Michelle pointed out, forums still use it, so I would want only my forum nodes to have a sticky flag on them.
In terms of performance however, only aggregates would be slowed down if they were sorted on non-global flags. And things like ALTER TABLE ADD COLUMN on 500K of nodes, is only gonna happen once, if its really going to be an issue, then recommend switching to maintenance mode for content type changes.
Comment #10
josh waihi commentedThere are two scopes to consider, global and per content type (for node), naturally a global flag can be added as a column to the node or node_revision table but per content type would require another table to join, slowing things down a bit. For example, I never use sticky and don't see the use for it, but as Michelle pointed out, forums still use it, so I would want only my forum nodes to have a sticky flag on them.
In terms of performance however, only aggregates would be slowed down if they were sorted on non-global flags. And things like ALTER TABLE ADD COLUMN on 500K of nodes, is only gonna happen once, if its really going to be an issue, then recommend switching to maintenance mode for content type changes.
Comment #11
yched commentedhook_field_storage_pre_*() hooks can be used to bypass regular storage. So technically having fields 'status', 'sticky' etc... stored in {node} is possible.
Such a move would notably mean that
- $node->status becomes $node->status[0]['value']
- those flags become revisioned [edit: er, ok, probably not if stored on {node}]
I'm not sure I see what this would really buy us, though...
Comment #12
josh waihi commentedI was gonna write up a patch to get things rolling but seen as I've never written a cck field before and field.api.inc has too many TODOs in it to be able to figure out how to implement this, I'm just gonna describe the spec for flag field instead.
The flag field will be an effort to solve several issues surrounding flag type facets within objects like $node and $user. These issues include, removing sticky and promoted from the node schema as they are not always needed. Adding status to revisions to show which are published and which are still in 'draft' (node.vid would still indicate which revision to show). As for users.blocked - I don't really see what benefit it would have as a flag field. Likewise, even though node.status is a yes/no field, it wouldn't make any sense turn it into a flag field.
In terms of database and performance, the flag field could create flags in 1 of two ways. Firstly, store flags in its own table which would require joining - this would be used when flag field didn't know how to do the second option that is to alter a table such as node, node_revision or users and add the column - this is rather useful as many flags are used as a means to filter data, eg status,promote,blocked,abuse. So naturally, a flag field would also be indexed by default (UI could offer an opt-out option). Because there is potential that a user could add a flag field to a node table that has a billion rows, we could add a check along to lines of if (count > scary number) suggest maintenance mode.
Keeping in mind that sticky is used by forums, the forum install hook could create the sticky flag if not already installed. This also leads to ideas like having default fields that are disabled by default when drupal installs but can be turned on by a user or a module such as forum.
I think that covers everything Catch and I discussed. I leave you with this http://www.youtube.com/watch?v=hYeFcSq7Mxg
Comment #13
yched commentedre Josh Waihi #12: "I was gonna write up a patch but field.api.inc has too many TODOs in it to be able to figure out how to implement this"
heh, I cannot leave that unanswered ;-). Working on the missing doc bits, stay tuned.
Comment #14
yched commentedpatch for Field type API docs in #528182: Field type API docs :-p
Comment #15
sun.core commentedComment #16
jhedstromFeature -> 8.1.
This thread seems to have lost momentum, and much has changed in the interim. Marking postponed for now.
Comment #28
pasqualleComment #29
longwaveAll three of these are boolean base fields now, I think that is the closest to a "flag" field that we have in core - I suggest this can be closed as outdated.
Comment #31
catchMarking duplicate of #29338: Hide Promoted/Sticky fields by default in Form display.