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

UBER-218: Fix createOn -> createdOn #3266

Merged
merged 1 commit into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions models/chunter/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export async function migrateThreadMessages (client: MigrationClient): Promise<v
modifiedOn: message.modifiedOn,
modifiedBy: message.modifiedBy,
createBy: message.modifiedBy,
createOn: message.modifiedOn,
createdOn: message.modifiedOn,
_id: message._id as string as Ref<ThreadMessage>
})
}
Expand All @@ -156,7 +156,7 @@ export async function migrateThreadMessages (client: MigrationClient): Promise<v
{
objectClass: chunter.class.ThreadMessage,
'attributes.createBy': tx.modifiedBy,
'attributes.createOn': tx.modifiedOn,
'attributes.createdOn': tx.modifiedOn,
'attributes.content': tx.attributes.message
}
)
Expand Down
2 changes: 1 addition & 1 deletion models/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class TDoc extends TObj implements Doc {

@Prop(TypeTimestamp(), core.string.CreatedDate)
@ReadOnly()
createOn!: Timestamp
createdOn!: Timestamp
}

@Model(core.class.AttachedDoc, core.class.Doc)
Expand Down
11 changes: 7 additions & 4 deletions models/core/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ async function fillCreatedOn (client: MigrationClient): Promise<void> {
) {
continue
}

await client.update<Doc>(domain, { createOn: { $exists: true } }, { $unset: { createOn: 1 } })

while (true) {
try {
const objects = await client.find<Doc>(
Expand All @@ -115,7 +118,7 @@ async function fillCreatedOn (client: MigrationClient): Promise<void> {
_class: core.class.TxCreateDoc,
objectId: { $in: Array.from(objects.map((it) => it._id)) }
},
{ projection: { _id: 1, modifiedOn: 1, createOn: 1, objectId: 1 } }
{ projection: { _id: 1, modifiedOn: 1, createdOn: 1, objectId: 1 } }
)

const txes2 = (
Expand All @@ -126,21 +129,21 @@ async function fillCreatedOn (client: MigrationClient): Promise<void> {
'tx._class': core.class.TxCreateDoc,
'tx.objectId': { $in: Array.from(objects.map((it) => it._id)) }
},
{ projection: { _id: 1, modifiedOn: 1, createOn: 1, tx: 1 } }
{ projection: { _id: 1, modifiedOn: 1, createdOn: 1, tx: 1 } }
)
).map((it) => it.tx as unknown as TxCreateDoc<Doc>)

const txMap = new Map(txes.concat(txes2).map((p) => [p.objectId, p]))

console.log('migrateCreateOn', domain, objects.length)
console.log('migratecreatedOn', domain, objects.length)
await client.bulk(
domain,
objects.map((it) => {
const createTx = txMap.get(it._id)
return {
filter: { _id: it._id },
update: {
createdOn: createTx?.createOn ?? it.modifiedOn
createdOn: createTx?.createdOn ?? it.modifiedOn
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion models/lead/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export function createModel (builder: Builder): void {
orderBy: [
['state', SortingOrder.Ascending],
['modifiedOn', SortingOrder.Descending],
['createOn', SortingOrder.Descending],
['createdOn', SortingOrder.Descending],
['dueDate', SortingOrder.Ascending],
['rank', SortingOrder.Ascending]
],
Expand Down
2 changes: 1 addition & 1 deletion models/recruit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ export function createModel (builder: Builder): void {
orderBy: [
['state', SortingOrder.Ascending],
['modifiedOn', SortingOrder.Descending],
['createOn', SortingOrder.Descending],
['createdOn', SortingOrder.Descending],
['dueDate', SortingOrder.Ascending],
['rank', SortingOrder.Ascending]
],
Expand Down
8 changes: 4 additions & 4 deletions models/tracker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ export function createModel (builder: Builder): void {
['status', SortingOrder.Ascending],
['priority', SortingOrder.Ascending],
['modifiedOn', SortingOrder.Descending],
['createOn', SortingOrder.Descending],
['createdOn', SortingOrder.Descending],
['dueDate', SortingOrder.Ascending],
['rank', SortingOrder.Ascending]
],
Expand Down Expand Up @@ -592,7 +592,7 @@ export function createModel (builder: Builder): void {
['status', SortingOrder.Ascending],
['priority', SortingOrder.Ascending],
['modifiedOn', SortingOrder.Descending],
['createOn', SortingOrder.Descending],
['createdOn', SortingOrder.Descending],
['dueDate', SortingOrder.Ascending]
],
groupDepth: 1,
Expand Down Expand Up @@ -1780,7 +1780,7 @@ export function createModel (builder: Builder): void {
orderBy: [
['modifiedOn', SortingOrder.Descending],
['targetDate', SortingOrder.Descending],
['createOn', SortingOrder.Descending]
['createdOn', SortingOrder.Descending]
],
other: [showColors]
}
Expand Down Expand Up @@ -1852,7 +1852,7 @@ export function createModel (builder: Builder): void {
groupBy: ['lead'],
orderBy: [
['modifiedOn', SortingOrder.Descending],
['createOn', SortingOrder.Descending]
['createdOn', SortingOrder.Descending]
],
other: [showColors]
}
Expand Down
18 changes: 11 additions & 7 deletions models/view/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ async function migrateViewletPreference (client: MigrationClient): Promise<void>
}

async function migrateSavedFilters (client: MigrationClient): Promise<void> {
await client.move(
DOMAIN_PREFERENCE,
{
_class: view.class.FilteredView
},
DOMAIN_VIEW
)
try {
await client.move(
DOMAIN_PREFERENCE,
{
_class: view.class.FilteredView
},
DOMAIN_VIEW
)
} catch (err: any) {
console.log(err)
}
const preferences = await client.find<FilteredView>(DOMAIN_VIEW, {
_class: view.class.FilteredView,
users: { $exists: false }
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface Doc extends Obj {
modifiedOn: Timestamp
modifiedBy: Ref<Account>
createdBy?: Ref<Account> // Marked as optional since it will be filled by platform.
createOn?: Timestamp // Marked as optional since it will be filled by platform.
createdOn?: Timestamp // Marked as optional since it will be filled by platform.
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export abstract class TxProcessor implements WithTx {
modifiedBy: tx.modifiedBy,
modifiedOn: tx.modifiedOn,
createdBy: tx.createdBy ?? tx.modifiedBy,
createOn: tx.createOn ?? tx.modifiedOn
createdOn: tx.createdOn ?? tx.modifiedOn
} as T
}

Expand Down
6 changes: 3 additions & 3 deletions plugins/chunter-resources/src/components/Channel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
if (docUpdate === undefined || lastView === undefined) return -1
for (let index = 0; index < messages.length; index++) {
const message = messages[index]
if ((message.createOn ?? 0) >= lastView) return index
if ((message.createdOn ?? 0) >= lastView) return index
}
return -1
}
Expand Down Expand Up @@ -209,8 +209,8 @@
{#if newMessagesPos === i}
<ChannelSeparator title={chunter.string.New} line reverse isNew />
{/if}
{#if i === 0 || isOtherDay(message.createOn ?? 0, messages[i - 1].createOn ?? 0)}
<JumpToDateSelector selectedDate={message.createOn} on:jumpToDate={handleJumpToDate} />
{#if i === 0 || isOtherDay(message.createdOn ?? 0, messages[i - 1].createdOn ?? 0)}
<JumpToDateSelector selectedDate={message.createdOn} on:jumpToDate={handleJumpToDate} />
{/if}
<MessageComponent
isHighlighted={$messageIdForScroll === message._id && $isMessageHighlighted}
Expand Down
2 changes: 1 addition & 1 deletion plugins/chunter-resources/src/components/Message.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
{#if employee}
<EmployeePresenter value={employee} shouldShowAvatar={false} inline />
{/if}
<span>{getTime(message.createOn ?? 0)}</span>
<span>{getTime(message.createdOn ?? 0)}</span>
{#if message.editedOn}
<span use:tooltip={{ label: ui.string.TimeTooltip, props: { value: getTime(message.editedOn) } }}>
<Label label={chunter.string.Edited} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
...resultQuery
},
{
sort: { createOn: SortingOrder.Descending },
sort: { createdOn: SortingOrder.Descending },
limit: 100,
lookup: {
_id: { attachments: attachment.class.Attachment },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
</div>
</div>
<MessageViewer message={message.content} />
<span class="time">{getTime(message.createOn ?? 0)}</span>
<span class="time">{getTime(message.createdOn ?? 0)}</span>
</div>
{/each}
</div>
Expand Down
2 changes: 1 addition & 1 deletion plugins/chunter-resources/src/components/Thread.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
const options: FindOptions<ThreadMessage> = {
lookup,
sort: {
createOn: SortingOrder.Descending
createdOn: SortingOrder.Descending
},
total: true
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/chunter-resources/src/components/ThreadView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
if (docUpdate === undefined || lastView === undefined) return -1
for (let index = 0; index < comments.length; index++) {
const comment = comments[index]
if ((comment.createOn ?? 0) >= lastView) return index
if ((comment.createdOn ?? 0) >= lastView) return index
}
return -1
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/chunter-resources/src/components/Threads.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
{
sort: {
createOn: SortingOrder.Descending
createdOn: SortingOrder.Descending
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
...resultQuery
},
{
sort: { createOn: SortingOrder.Descending },
sort: { createdOn: SortingOrder.Descending },
limit: 100,
lookup: { _id: { statuses: contact.class.Status } }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
$: resultChannels = mergeChannels(oldChannels, targetChannels, enabledChannels)

const attributes = hierarchy.getAllAttributes(contact.class.Employee, core.class.Doc)
const ignoreKeys = ['name', 'avatar', 'createOn']
const ignoreKeys = ['name', 'avatar', 'createdOn']
const objectAttributes = Array.from(attributes.entries()).filter(
(p) => !p[1].hidden && !ignoreKeys.includes(p[0]) && !isCollectionAttr(hierarchy, { key: p[0], attr: p[1] })
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
'tx.attributes.incoming': false
},
(res) => {
const filtered = res.filter((p) => (p.tx as TxCreateDoc<ChannelItem>).attributes.sendOn >= (object.createOn ?? 0))
const filtered = res.filter(
(p) => (p.tx as TxCreateDoc<ChannelItem>).attributes.sendOn >= (object.createdOn ?? 0)
)
newTxes = createDisplayTxes(filtered)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@

// Store all extra values.
for (const [k, v] of Object.entries(object)) {
if (v != null && k !== 'createOn' && k !== 'avatar') {
if (v != null && k !== 'createdOn' && k !== 'avatar') {
const attr = hierarchy.findAttribute(recruit.mixin.Candidate, k)
if (attr === undefined) continue
if (attr.attributeOf === recruit.mixin.Candidate) {
Expand Down
3 changes: 2 additions & 1 deletion server-plugins/chunter-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ async function ThreadMessageDelete (tx: Tx, control: TriggerControl): Promise<Tx
comment.attachedTo,
{
replies: comments.map((comm) => (control.modelDb.getObject(comm.createBy) as EmployeeAccount).employee),
lastReply: comments.length > 0 ? Math.max(...comments.map((comm) => comm.createOn ?? comm.modifiedOn)) : undefined
lastReply:
comments.length > 0 ? Math.max(...comments.map((comm) => comm.createdOn ?? comm.modifiedOn)) : undefined
}
)

Expand Down
2 changes: 1 addition & 1 deletion server-plugins/gmail-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export async function IsIncomingMessage (
control: TriggerControl
): Promise<boolean> {
const message = TxProcessor.createDoc2Doc(TxProcessor.extractTx(tx) as TxCreateDoc<Message>)
return message.incoming && message.sendOn > (doc.createOn ?? doc.modifiedOn)
return message.incoming && message.sendOn > (doc.createdOn ?? doc.modifiedOn)
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
Expand Down
2 changes: 1 addition & 1 deletion server-plugins/telegram-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export async function IsIncomingMessage (
control: TriggerControl
): Promise<boolean> {
const message = TxProcessor.createDoc2Doc(TxProcessor.extractTx(tx) as TxCreateDoc<TelegramMessage>)
return message.incoming && message.sendOn > (doc.createOn ?? doc.modifiedOn)
return message.incoming && message.sendOn > (doc.createdOn ?? doc.modifiedOn)
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
Expand Down
2 changes: 1 addition & 1 deletion server/middleware/src/modified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ModifiedMiddleware extends BaseMiddleware implements Middleware {
async tx (ctx: SessionContext, tx: Tx): Promise<TxMiddlewareResult> {
if (tx.modifiedBy !== core.account.System) {
tx.modifiedOn = Date.now()
tx.createOn = tx.createOn ?? tx.modifiedOn
tx.createdOn = tx.createdOn ?? tx.modifiedOn
}
return await this.provideTx(ctx, tx)
}
Expand Down
2 changes: 1 addition & 1 deletion server/mongo/src/__tests__/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const doc1: Task = {
rate: 20,
modifiedBy: 'user' as Ref<Account>,
modifiedOn: 10,
// createOn: 10,
// createdOn: 10,
space: '' as Ref<Space>
}

Expand Down