Dataview for modified date array field in properties - list only last element (and performance issue)

What I’m trying to do

I want to list all notes modified today, with a dataview in my Daily Notes with columns: filename, creation date, modification date/time.

I am not using cdate, mdate in my notes, but my own properties:

  • createdDate (initialized by daily note template)
  • modifiedDateTime (initialized and updated by this plugin.

(The reason for using my fields is that cdate and mdate are affected by operating system events, cloud sync and so on, and I want to keep my fields consistent alog time).

The portion of Frontmatter including the dates is for instance as follows:

createdDate: 2023-10-23
createdTime: 15:36
modifiedDateTime:
  - 2023-10-23 15:44
  - 2023-10-23 16:33
  - 2023-11-08 17:01
  - 2023-11-18 16:02

modifiedDateTime is an array because it keeps the history of modifications (maximum 1 per day).

I would like to list only the last entry of the array in order not to have a long list of modifications in dataview.

Present solution

My dataview is:

TABLE WITHOUT ID
  link(file.link) AS "File name", file.frontmatter.createdDate AS "Created", 
file.frontmatter.modifiedDateTime as "Modified" WHERE file.name != 
this.file.name and contains(file.frontmatter.modifiedDateTime,this.file.frontmatter.createdDate) sort 
file.frontmatter.modifiedDateTime

This dataview lists all the array elements and the table is hardly readable.


As a further problem, the performance is not good, i takes about 30 seconds to open the daily note with ~1000 notes in vault.

I’d try something like the following:

```dataview 
TABLE WITHOUT ID 
  link(file.link) AS "File name",
  createdDate AS "Created",
  lastModified as "Modified"
FLATTEN max(modifiedDateTime) as lastModified
WHERE file.name != this.file.name
SORT lastModified desc
LIMIT 20
```

Here I use max() on the modified list to get the last value (aka most recent), and sort with the last modified files first. I’m also just showing the 20 most recent files.

Not sure why you checked whether the creation date contained the modification dates so I dropped that line… :slight_smile:

Thank you @holroy , it works.

I check whether the modification date (array) contains the creation date in order to obtain
the list of notes modified today.

So finally this is the query:

TABLE WITHOUT ID
link(file.link) AS "File name", file.frontmatter.createdDate AS "Created", 
max(file.frontmatter.modifiedDateTime) as "Modified" 
WHERE file.name != this.file.name and contains(file.frontmatter.modifiedDateTime,this.file.frontmatter.createdDate) 
sort file.frontmatter.modifiedDateTime desc

What remains open is the performance issue, the creation of the new Diary note is still very slow.

I’m not sure, but there is something fishy about that check. First of all since the date format is not a valid format as it lacks the “T” inbetween the date and the time stamp. Secondly, as even if it understood that invalid date format it shouldn’t match a pure date against a date+time field. It might be working due to modifiedDateTime being interpreted as a string, so it converts the createdDate into a string before checking the contained. If so, this might be part of the cause for your performance issues.

It’s hard to say, as it shouldn’t really be that hard either way. But do you say the creation of the daily note takes long? If so, there might be other stuff in your template causing that. The query isn’t executed until you view the already created note.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.