Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model published and/or updated *(similar to created)* field #349

Closed
Zren opened this issue Sep 16, 2014 · 12 comments · Fixed by #1749
Closed

Model published and/or updated *(similar to created)* field #349

Zren opened this issue Sep 16, 2014 · 12 comments · Fixed by #1749
Labels
DB Pertains inclusively to the Database operations. enhancement Something we do have implemented already but needs improvement upon to the best of knowledge. migration Use this to indicate that it may apply to an existing or announced migration. UI Pertains inclusively to the User Interface.

Comments

@Zren
Copy link
Contributor

Zren commented Sep 16, 2014

With MongoDB. _id: { type: ObjectId } (which is the default id type) is made up of a timestamp of when the object was created (plus a few other things to make it unique across servers when you distribute the db). We can use it right now to fetch the creation date of scripts and other models.

It's currently possible to sort by creation date like so:
https://openuserjs.org/?orderBy=_id&orderDir=asc

To display it, we can use _id.getTimestamp(), but I think making a virtual (OWNER EDITED: static stored) property BaseSchema.created would be best.

@Zren Zren added DB Pertains inclusively to the Database operations. UI Pertains inclusively to the User Interface. enhancement Something we do have implemented already but needs improvement upon to the best of knowledge. labels Sep 16, 2014
@Zren Zren self-assigned this Sep 16, 2014
@jerone
Copy link
Contributor

jerone commented Nov 24, 2014

I used a Mongoose plugin called mongoose-timestamp before, which adds createdAt and updatedAt date attributes that get auto-assigned to the most recent create/update timestamp.

Aldo this is not backwards compatible, it might be good practice to use it for every model.

Thinking about it, it may be backwards compatible for the script & discussion & group models with some routing to _id.getTimestamp() and existing updated. Other models are incompatible, but still useful.

@Zren Zren removed their assignment Nov 24, 2014
@Zren
Copy link
Contributor Author

Zren commented Nov 25, 2014

Plugin looks nice, but we wouldn't want Script.updatedAt to reperesent Script.updated in it's current context as the Script model is updated every time someone installs a script. It should probably be called Script.sourceCodeUpdateAt. It'd be very useful for the Discussion/Comment models.

@Martii
Copy link
Member

Martii commented Aug 7, 2015

@Zren

Sorry didn't (recall) seeing this ticket and probably didn't understand it at the time it was posted...anywhooo...

Which other models did you want this added to?

I already added it to Script and User (models) in #485... we should continue to use _since as the virtual property name... and did you want to do anything different on the hard-coded dates? I may have to email sizzle to see if his commenting routine (Discussion and Comment) will be blocking since he is assigned to that as well as Vote ... and the virtual will currently need to check the existing creation date property first and return that instead.

@Zren
Copy link
Contributor Author

Zren commented Aug 7, 2015

Every single model can benifit from a createdAt and updatedAt column. You can't query over virtual functions (and we shouldn't really be querying on ObjectId since it includes other stuff). You can sort to find a new discussions, new votes, new groups, new ____.

did you want to do anything different on the hard-coded dates?

Eh? Are you talking about ObjectId.getTimestamp()? All I would use it for is populating the createdAt column if it was added.

@Martii
Copy link
Member

Martii commented Aug 7, 2015

You can't query over virtual functions

Please cite reference for this from mongoose package API docs. I'll try a query at some point in the near future to confirm. Thanks.

All I would use it for is populating the createdAt column if it was added.

Depending on the citation and testing... this is doable... although if "createAt" isn't necessary we should avoid hard-coding it into the schema.

@Martii Martii added mightfix Ehh maybe... convince us all... needs testing Anyone can add this but it is primarily there for the Assignee indicating that Testers are wanted. labels Aug 7, 2015
@Zren
Copy link
Contributor Author

Zren commented Aug 7, 2015

Virtual functions aren't serialized into the db, nor are their calculated values, ergo you can't query over them.

http://mongoosejs.com/docs/guide.html#virtuals

@Martii
Copy link
Member

Martii commented Aug 7, 2015

http://mongoosejs.com/docs/guide.html#virtuals

"Only non-virtual properties work as part of queries and for field selection."

Thank you... elusive documentation and some contradicting elsewhere... also found setters there... good to know... will need to ponder on the relevance of sorting on creation date... not sure I see a need for that right off. (Anyone) Got any other use cases where we might be able to use this?


Paraphrased quote for today:

"Just because we can do something, doesn't necessarily mean that we should do something"

@Martii
Copy link
Member

Martii commented Aug 7, 2015

@jerone

I used a Mongoose plugin called mongoose-timestamp before...

I'm a little concerned with the issue on that repo at issue 26 ... would you validate that please? (no rush just when you have some time) I'd rather not add a dep (plugin) that might be considered abandonware... current last update is Feb 28, 2015... but he is active elsewhere. mongoose 3ish support is scheduled to be EOL'd in Sept 2015 and no backports of newer features are being made available at this time from what I've read.

@Martii Martii added migration Use this to indicate that it may apply to an existing or announced migration. and removed needs testing Anyone can add this but it is primarily there for the Assignee indicating that Testers are wanted. labels Aug 7, 2015
@Martii
Copy link
Member

Martii commented Oct 18, 2015

@Zren
Another misc thought... this idea is good if we ever migrate the database from one db to another to maintain the creation date in case _id ever changes but the likelihood is up to sizzle. The _since virtuals seem to be working well and I still can't think of a reason why we would want to sort on creation date... but will ponder it some more.

@Martii Martii changed the title Script.created Model published *(similar to created) field Nov 24, 2015
@Martii Martii added the later A long time ahead, in a galaxy near, near... label Nov 24, 2015
@Martii
Copy link
Member

Martii commented Nov 24, 2015

@Zren
I've renamed this issue to be a little more encompassing. I can see a possible Moderator and above usage for checking for new User profile spammers. This is still being pondered but the scales are tipping a little bit. Tagged later label as there are much other higher priority issues to handle first.

The difference between published and created is simple... published means first appearance on OUJS (and could be a later revision like a book) whereas created could mean first instance ever of something, like a script, which is why I chose "Published" because it might be the first time on OUJS but the script could have been around for ages.

@Martii Martii changed the title Model published *(similar to created) field Model published *(similar to created)* field Nov 25, 2015
@Martii Martii changed the title Model published *(similar to created)* field Model published and/or updated *(similar to created)* field Nov 25, 2015
@Martii
Copy link
Member

Martii commented Nov 25, 2015

Still might do updated... this would detect existing accounts with those who updated it later... if implemented this will be hardcoded into the db as a static property and not a virtual for sure.

This was referenced Oct 29, 2019
@Martii Martii removed later A long time ahead, in a galaxy near, near... mightfix Ehh maybe... convince us all... labels Aug 29, 2020
@Martii Martii self-assigned this Aug 29, 2020
@Martii
Copy link
Member

Martii commented Aug 29, 2020

Status of this has changed due to additional testing. Not that we need extra columns (which are already pushing it on portables) but the precision of _since omits the milliseconds. There is also a concern that in a few dozen years, yes years, _since will have an issue similar to Y2K... guess the engineers didn't learn from this the first time i.e. clock wrap or just general failure of it.

I'll add a few created and updated fields to some of the models hopefully next week and begin a DB migration of the less-precise values.

Martii added a commit to Martii/OpenUserJS.org that referenced this issue Sep 4, 2020
* `_since` has a precision issue and possible extended time failure due to lack of bits
* Fix a few timing issues
* Best not to set default date in groups model as it can cover up errors and was doing it twice
* Some identifier symmetry
* All models should have base `created` with the exception of `removed` since once gone that's technically creation of nothingness.
* Bump package version since older backups won't be valid after migration

Applies to OpenUserJS#349
Martii added a commit that referenced this issue Sep 4, 2020
* `_since` has a precision issue and possible extended time failure due to lack of bits
* Fix a few timing issues
* Best not to set default date in groups model as it can cover up errors and was doing it twice
* Some identifier symmetry
* All models should have base `created` with the exception of `removed` since once gone that's technically creation of nothingness.
* Bump package version since older backups won't be valid after migration

Applies to #349

Auto-merge
Martii added a commit to Martii/OpenUserJS.org that referenced this issue Sep 4, 2020
Martii added a commit that referenced this issue Sep 4, 2020
Applies to #349

Auto-merge
Martii added a commit to Martii/OpenUserJS.org that referenced this issue Sep 4, 2020
* Change some UI centering.
* If new columns for `created` and/or `updated` are wanted please open a new issue with relativity.
* Since queries can be CPU intensive continue to limit some of these in the UI.
* MongoDB 4.x has the ability to auto-create these per save/creation however finite control is usually needed rather than all the time/everywhere.

Applies to OpenUserJS#485 and closes OpenUserJS#349
Martii added a commit that referenced this issue Sep 4, 2020
* Change some UI centering.
* If new columns for `created` and/or `updated` are wanted please open a new issue with relativity.
* Since queries can be CPU intensive continue to limit some of these in the UI.
* MongoDB 4.x has the ability to auto-create these per save/creation however finite control is usually needed rather than all the time/everywhere.

Applies to #485 and closes #349

Auto-merge
@Martii Martii removed their assignment Sep 4, 2020
@OpenUserJS OpenUserJS locked as resolved and limited conversation to collaborators Apr 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
DB Pertains inclusively to the Database operations. enhancement Something we do have implemented already but needs improvement upon to the best of knowledge. migration Use this to indicate that it may apply to an existing or announced migration. UI Pertains inclusively to the User Interface.
Development

Successfully merging a pull request may close this issue.

3 participants