Skip to content

A simple method for providing a quick/dirty reload option (refs #990) - #997

Merged
waylan merged 1 commit into
mkdocs:masterfrom
aeslaughter:dirty
Jul 27, 2016
Merged

waylan merged 1 commit into
mkdocs:masterfrom
aeslaughter:dirty

Conversation

@aeslaughter

Copy link
Copy Markdown
Contributor

This provides a --dirty-reload option to the serve command. It simply operates by comparing the modified time of the markdown and html. This is a much simpler solution to what was proposed in
#971 and is meeting my needs well.

Note, that there was some discussion of --clean/--no-clean with the serve command. However, passing a --clean/--no-clean option to the serve command doesn't do anything since each time it runs is creates a different tmp directory (at least for me). So, effectively it is always clean.

(closes #990)

@waylan

waylan commented Jul 21, 2016

Copy link
Copy Markdown
Contributor

I agree, this is much simpler than a cache system and most likely all we need (comparing modified times using the existing features of the file system). I think I like it. I'll need to look at the specific implementation more closely later (I'm preparing to leave for a long weekend today). But, a few quick things I noticed:

Could we also add a --dirty flag to the build command which does the same thing? As I stated in #990:

This would actually be pretty easy. Boolean Flags can support two flags to enable/disable a feature. We can just add the second flag and change the default to be --clean. We don't even need to deprecate anything.

Also, would it make sense to have --dirty-reload be a third option with --livereload/--no-livereload? (we'd need to change it from a Boolean Flag to a Feature Switch in order to support three options) It seems kind of silly to have both --livereload --dirty-reload in the same command. Obviously --dirty-reload implies --livereload, so why make it necessarily redundant. And yes, I realize that because --livereload is the default, users don't actually need to use both flags. I'm just trying to keep the interface clean. As an added benefit, using --no-livereload --dirty-reload in the same command would (and should) generate an error, which would be less confusing to users.

Finally, I'm curious; how much does this affect performance on a large site? How noticeable of a difference is there? Actually, if we add the --dirty flag to the build command, I imagine we could benchmark the builds (--dirty vs. --clean) relatively easily.

@aeslaughter

Copy link
Copy Markdown
Contributor Author

@waylan I will make the changes you suggest.

Finally, I'm curious; how much does this affect performance on a large site? How noticeable of a difference is there? Actually, if we add the --dirty flag to the build command, I imagine we could benchmark the builds (--dirty vs. --clean) relatively easily.

My initial build of the site takes about 3 min. and re-building a single file takes almost nothing, which makes live editing possible.

@waylan

waylan commented Jul 21, 2016

Copy link
Copy Markdown
Contributor

My initial build of the site takes about 3 min. and re-building a single file takes almost nothing

Wow, that seems significant. As I have only ever used MkDocs for smaller projects, sometimes I forget about how build times can affect workflow for larger projects. A 3 min wait for every save would be untenable... But the real reason I asked was to check that these changes were actually shortening the build time as the current exclude-the-clean-flag approach does not actually shorten the build time (as you know).

As I mentioned earlier, I'll be out of town this weekend (leaving in a hour or two), so I'll review more closely next week, unless @d0ugal beats me to it.

@aeslaughter

aeslaughter commented Jul 21, 2016 •

Copy link
Copy Markdown
Contributor Author

The latest push includes the command-line argument improvements, including a --dirty flag for the build command.

Initial build:

time mkdocs build
INFO    -  Building documentation to directory: /Users/slauae/projects/moose-doc/site 

real    2m39.405s
user    2m15.570s
sys 0m23.849s

Dirty build (changing single file):

time mkdocs build --dirty
INFO    -  Building documentation to directory: /Users/slauae/projects/moose-doc/site 
INFO    -  The directory contains stale files. Use --clean to remove them. 

real    0m2.405s
user    0m1.481s
sys 0m0.901s

I also have a long weekend, so no-worries about getting this finished up next week. Thanks.

Comment thread mkdocs/__main__.py Outdated


clean_help = "Remove old files from the site_dir before building"
dirty_reload_help = "Only re-build files that have changed when livereload is enabled"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redefined later. This line should be removed.

@waylan

waylan commented Jul 25, 2016

Copy link
Copy Markdown
Contributor

This is looking good. Although, I'm wondering if maybe we should issue a warning when --dirty is used. With --clean being the default, it should not be much of a problem, but it wouldn't hurt to issue the warning on --dirty anyway. Some users may not understand the tradeoffs and a warning that the current state may contain errors in navigation/etc would be helpful.

It just occurred to me that this ignores media files (in the site_dir) and static assets (in the theme). Those are still being re-copied each time. I suppose if a user has large images/videos/etc, it would be useful to be able to skip those on reloads. We might want to pass dirty on to utils.copy_media_files and/or utils.copy_file. We could address static assets as well, but those are more likely to be rather minimal in comparison.

Also, we need the release notes updated. This should be noted in the major changes section as a default behavior is being changed.

@aeslaughter

aeslaughter commented Jul 25, 2016 •

Copy link
Copy Markdown
Contributor Author

The latest push adds a warning, dirty flags for the copy methods, and moves the modified time function to utils.

One thing I noticed, is the copy_files function doesn't seem to be used anywhere.

Comment thread mkdocs/commands/build.py Outdated
)

log.debug("Copying static assets from the docs dir.")
utils.copy_media_files(config['docs_dir'], config['site_dir'])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to pass the value of dirty on here? Same applies to any other calls to this function or utils.copy_file.

@waylan

waylan commented Jul 25, 2016

Copy link
Copy Markdown
Contributor

One thing I noticed, is the copy_files function doesn't seem to be used anywhere.

I assume you mean copy_file (no 's'). In any event, you're right. Lets just merge that into the utils.copy_media_files function.

@aeslaughter

aeslaughter commented Jul 25, 2016 •

Copy link
Copy Markdown
Contributor Author

I assume you mean copy_file (no 's'). In any event, you're right. Lets just merge that into the utils.copy_media_files function.

So, copy_file is called in copy_media_files (I searched for copy_files), so doing the check in copy_media_files alone should be enough, I think this is what you were wanting.

Comment thread mkdocs/commands/build.py Outdated
log.info("The directory contains stale files. Use --clean to remove them.")

# Set the status of a dirtyreload feature, a build is considered 'dirty' if clean_site_dir = False
dirty = not clean_site_dir

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed this before, but let's just change the build function's argument from clean_site_dir=False to dirty=False. After all, we are changing the default, and the consistent API will be less confusing later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now changed and much better.

@waylan

waylan commented Jul 26, 2016 •

Copy link
Copy Markdown
Contributor

Looks good. Thanks for your work on this. If you could add a note to the release notes (docs/about/release-notes.md), I'll merge it.

I should note that the --clean flag is mentioned in docs/user-guide/deploying-your-docs.md. The purpose is not explained, but it appears in multiple examples. If doesn't really hurt anything to leave it there, but given the default has changed, its not necessary. If you are so inclined, updating the documentation would be appreciated as well.

@aeslaughter

Copy link
Copy Markdown
Contributor Author

@waylan I added some the requested documentation and release note updates. Give it a read to see if I made some typos. I put this in separate commit, let me know if you want me to squash it all together or not.

Comment thread docs/about/release-notes.md Outdated
```

It is important to note that this method for building the pages is for development
of content only, since the navigation and other links do not get updated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add "on other pages" to the end of this sentence (or something similar)? I just want to make it clear that just because the nav is correct on the "updated" page, that does not mean it is on others.

@waylan

waylan commented Jul 26, 2016

Copy link
Copy Markdown
Contributor

I prefer the documentation regarding a change to be with the associated changes, so if you could squash, that would be preferred. That said, I would have taken it as-is if it wasn't for the Markdown-lint error.

@aeslaughter

Copy link
Copy Markdown
Contributor Author

@waylan Should be good now, thanks for helping me get this in.

@waylan
waylan merged commit 2e4c2af into mkdocs:master Jul 27, 2016
@waylan

waylan commented Jul 27, 2016

Copy link
Copy Markdown
Contributor

@aeslaughter thanks for the work on this and your patience with my endless nitpicks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support partial builds with serve

2 participants